Re: Multithreaded SIGPIPE race in libpq on Solaris - Mailing list pgsql-hackers

From Tom Lane
Subject Re: Multithreaded SIGPIPE race in libpq on Solaris
Date
Msg-id 12130.1409265931@sss.pgh.pa.us
Whole thread Raw
In response to Multithreaded SIGPIPE race in libpq on Solaris  (Thomas Munro <munro@ip9.org>)
Responses Re: Multithreaded SIGPIPE race in libpq on Solaris
List pgsql-hackers
Thomas Munro <munro@ip9.org> writes:
> My theory is that if two connections accessed by different threads get
> shut down around the same time, there is a race scenario where each of
> them fails to write to its socket, sees errno == EPIPE and then sees a
> pending SIGPIPE with sigpending(), but only one thread returns from
> sigwait() due to signal merging.

Hm, that does sound like it could be a problem, if the platform fails
to track pending SIGPIPE on a per-thread basis.

> We never saw the problem again after we made the following change:
> ...
> Does this make any sense?

I don't think that patch would fix the problem if it's real.  It would
prevent libpq from hanging up when it's trying to throw away a pending
SIGPIPE, but the fundamental issue is that that action could cause a
SIGPIPE that's meant for some other thread to get lost; and that other
thread isn't necessarily doing anything with libpq.

I don't claim to be an expert on this stuff, but I had the idea that
multithreaded environments were supposed to track signal state per-thread
not just per-process, precisely because of issues like this.
        regards, tom lane



pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: Why data of timestamptz does not store value of timezone passed to it?
Next
From: Alvaro Herrera
Date:
Subject: Re: [BUGS] BUG #10823: Better REINDEX syntax.