postgresql/src
Heikki Linnakangas 0214a61e06 Fix potential deadlock with libpq non-blocking mode.
If libpq output buffer is full, pqSendSome() function tries to drain any
incoming data. This avoids deadlock, if the server e.g. sends a lot of
NOTICE messages, and blocks until we read them. However, pqSendSome() only
did that in blocking mode. In non-blocking mode, the deadlock could still
happen.

To fix, take a two-pronged approach:

1. Change the documentation to instruct that when PQflush() returns 1, you
should wait for both read- and write-ready, and call PQconsumeInput() if it
becomes read-ready. That fixes the deadlock, but applications are not going
to change overnight.

2. In pqSendSome(), drain the input buffer before returning 1. This
alleviates the problem for applications that only wait for write-ready. In
particular, a slow but steady stream of NOTICE messages during COPY FROM
STDIN will no longer cause a deadlock. The risk remains that the server
attempts to send a large burst of data and fills its output buffer, and at
the same time the client also sends enough data to fill its output buffer.
The application will deadlock if it goes to sleep, waiting for the socket
to become write-ready, before the server's data arrives. In practice,
NOTICE messages and such that the server might be sending are usually
short, so it's highly unlikely that the server would fill its output buffer
so quickly.

Backpatch to all supported versions.
2015-02-23 13:32:39 +02:00
..
backend Fix object identities for pg_conversion objects 2015-02-18 14:28:12 -03:00
bin Fix failure to honor -Z compression level option in pg_dump -Fd. 2015-02-18 11:43:00 -05:00
common Fix libpq's behavior when /etc/passwd isn't readable. 2015-01-11 12:35:47 -05:00
include Remove code to match IPv4 pg_hba.conf entries to IPv4-in-IPv6 addresses. 2015-02-17 12:49:18 -05:00
interfaces Fix potential deadlock with libpq non-blocking mode. 2015-02-23 13:32:39 +02:00
makefiles Remove USE_VPATH make variable from PGXS 2014-12-04 08:45:48 -05:00
pl Translation updates 2015-02-01 23:18:42 -05:00
port Improve pg_check_dir code and comments. 2015-02-17 10:50:49 -05:00
template Revert to using --enable-auto-import in Cygwin builds. 2014-02-16 15:14:04 -05:00
test Fix null-pointer-deref crash while doing COPY IN with check constraints. 2015-02-15 23:26:45 -05:00
timezone Update time zone data files to tzdata release 2015a. 2015-01-30 22:45:58 -05:00
tools Add pg_string_endswith as the start of a string helper library in src/common. 2015-01-03 20:54:13 +01:00
tutorial pgindent run for 9.4 2014-05-06 12:12:18 -04:00
.gitignore Convert cvsignore to gitignore, and add .gitignore for build targets. 2010-09-22 12:57:04 +02:00
bcc32.mak Autoconfiscate selection of 64-bit int type for 64-bit large object API. 2012-10-07 21:52:43 -04:00
DEVELOPERS Replace a couple of references to files that no longer exist in the source 2009-05-04 08:08:47 +00:00
Makefile Create libpgcommon, and move pg_malloc et al to it 2013-02-12 11:21:05 -03:00
Makefile.global.in Fix installcheck case for tap tests 2014-12-24 10:32:02 -05:00
Makefile.shlib MinGW: Include .dll extension in .def file LIBRARY commands. 2014-10-27 19:59:52 -04:00
nls-global.mk Setup error context callback for transaction lock waits 2014-03-19 15:10:36 -03:00
win32.mak Autoconfiscate selection of 64-bit int type for 64-bit large object API. 2012-10-07 21:52:43 -04:00