pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: noordsij <noordsij@cs.helsinki.fi>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Stefan Kaltenbrunner <stefan@kaltenbrunner.cc>
Cc: Alvaro Herrera <alvherre@commandprompt.com>
Cc: Robert Haas <robertmhaas@gmail.com>
Cc: Pg Bugs <pgsql-bugs@postgresql.org>
Subject: Re: BUG #6086: [SOLVED] Segmentation fault
Date: Wed, 27 Jul 2011 01:23:07 +0300
Message-ID: <68c429ede4cde3874b37460b5b1d4aaf@cs.helsinki.fi> (raw)
In-Reply-To: <13571.1311703637@sss.pgh.pa.us>
References: <201106300732.p5U7W0Bj001711@wwwmaster.postgresql.org>
	<CA+Tgmob6iFkry0Vg+whf2ALUaxYZAiSWCo8aDD5SH+9dzXad8A@mail.gmail.com>
	<e2e7673675e48059cf6712462467f4f6@cs.helsinki.fi>
	<CA+TgmoYo3BGBf1hh43FNyQ976HA4k_w5jexZnki8EEL+mHHhXw@mail.gmail.com>
	<1311609295-sup-6784@alvh.no-ip.org>
	<4E2DA57D.5010100@kaltenbrunner.cc>
	<f82ce27210f51a2faf8879d4f14e5cab@cs.helsinki.fi>
	<13571.1311703637@sss.pgh.pa.us>

> Linking pthreads into the backend is likely to cause more problems than
> it solves, especially if you're proposing that we do that everywhere.
> 
> 			regards, tom lane


No, I am not proposing that. Not linking to pthread when not needed should
actually be an
optimization since the libc noop stubs get used instead.

I've found the issue now (yes, again :)

Short version:
FreeBSD compiles the main server and contrib modules without and with
pthreads, respectively. No bug in postgresql. If you're in a hurry, no need
to read any further.


Longer version:
With FreeBSD ports, the contrib part is compiled separately. For some
reason, the contrib units are being made to link to pthread, but the server
itself isn't.

So the backend forks to handle a request, some stored procedure touches
some XML, libxml2 thinks it is initializing some mutex by calling some
pthread_ stubs in libc, the stored procedure updates a column which has a
trigram index, postgresql dynamically loads pg_trgm.so, which links to
libpthread, and now the weak libc symbols are overridden and a little bit
later we end up calling a real pthread_ method passing a non-initialized
mutex and get a bus error.

Lots of fun to debug, seeing pthread_self() suddenly changing return value
within a single thread/backend in the middle of processing a single
request..


With a custom (correct) compilation everything functions correctly with an
unmodified libxml2 and postgresql, and without any linking to or preloading
libpthread.

Question is, why are postgresql90-server and postgresql90-contrib compiled
differently ?

It seems it may have been intended as a quick fix for pgbench, as the
configure script for the -contrib port does not end up with "-pthread" in
the PTHREAD_CFLAGS in Makefile.global which breaks compilation of pgbench,
the server does have this, haven't found the reason yet. Side effect is
that all modules link to pthread while the server doesn't ..


I will continue this discussion within FreeBSD, as this is not a PostgreSQL
bug (though if there is ever a loadable contrib module which does need
pthreads the above situation will occur again).

Thanks again to all who helped!

Cheers
Dennis







Message-ID: <68c429ede4cde3874b37460b5b1d4aaf@cs.helsinki.fi>
Permalink:  ../68c429ede4cde3874b37460b5b1d4aaf@cs.helsinki.fi/
Also on:    postgresql.org/message-id/68c429ede4cde3874b37460b5b1d4aaf@cs.helsinki.fi

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: noordsij@cs.helsinki.fi, tgl@sss.pgh.pa.us, stefan@kaltenbrunner.cc, alvherre@commandprompt.com, robertmhaas@gmail.com
  Subject: Re: BUG #6086: [SOLVED] Segmentation fault
  In-Reply-To: <68c429ede4cde3874b37460b5b1d4aaf@cs.helsinki.fi>
  References: <201106300732.p5U7W0Bj001711@wwwmaster.postgresql.org> <CA+Tgmob6iFkry0Vg+whf2ALUaxYZAiSWCo8aDD5SH+9dzXad8A@mail.gmail.com> <e2e7673675e48059cf6712462467f4f6@cs.helsinki.fi> <CA+TgmoYo3BGBf1hh43FNyQ976HA4k_w5jexZnki8EEL+mHHhXw@mail.gmail.com> <1311609295-sup-6784@alvh.no-ip.org> <4E2DA57D.5010100@kaltenbrunner.cc> <f82ce27210f51a2faf8879d4f14e5cab@cs.helsinki.fi> <13571.1311703637@sss.pgh.pa.us> <68c429ede4cde3874b37460b5b1d4aaf@cs.helsinki.fi>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox