pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
pgsql: Fix unwanted flushing of libpq's input buffer when socket EOF is
4+ messages / 1 participants
[nested] [flat]

* pgsql: Fix unwanted flushing of libpq's input buffer when socket EOF is
@ 2015-11-12 18:04  Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 4+ messages in thread

From: Tom Lane @ 2015-11-12 18:04 UTC (permalink / raw)
  To: pgsql-committers

Fix unwanted flushing of libpq's input buffer when socket EOF is seen.

In commit 210eb9b743c0645d I centralized libpq's logic for closing down
the backend communication socket, and made the new pqDropConnection
routine always reset the I/O buffers to empty.  Many of the call sites
previously had not had such code, and while that amounted to an oversight
in some cases, there was one place where it was intentional and necessary
*not* to flush the input buffer: pqReadData should never cause that to
happen, since we probably still want to process whatever data we read.

This is the true cause of the problem Robert was attempting to fix in
c3e7c24a1d60dc6a, namely that libpq no longer reported the backend's final
ERROR message before reporting "server closed the connection unexpectedly".
But that only accidentally fixed it, by invoking parseInput before the
input buffer got flushed; and very likely there are timing scenarios
where we'd still lose the message before processing it.

To fix, pass a flag to pqDropConnection to tell it whether to flush the
input buffer or not.  On review I think flushing is actually correct for
every other call site.

Back-patch to 9.3 where the problem was introduced.  In HEAD, also improve
the comments added by c3e7c24a1d60dc6a.

Branch
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/c405918858c09d4264ffc5a3c73d57dc3efb0213

Modified Files
--------------
src/interfaces/libpq/fe-connect.c   |   38 ++++++++++++++++++++---------------
src/interfaces/libpq/fe-exec.c      |   17 +++++++++-------
src/interfaces/libpq/fe-misc.c      |    3 ++-
src/interfaces/libpq/fe-protocol3.c |    4 ++--
src/interfaces/libpq/libpq-int.h    |    2 +-
5 files changed, 37 insertions(+), 27 deletions(-)


-- 
Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-committers


^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* pgsql: Fix unwanted flushing of libpq's input buffer when socket EOF is
@ 2015-11-12 18:04  Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 4+ messages in thread

From: Tom Lane @ 2015-11-12 18:04 UTC (permalink / raw)
  To: pgsql-committers

Fix unwanted flushing of libpq's input buffer when socket EOF is seen.

In commit 210eb9b743c0645d I centralized libpq's logic for closing down
the backend communication socket, and made the new pqDropConnection
routine always reset the I/O buffers to empty.  Many of the call sites
previously had not had such code, and while that amounted to an oversight
in some cases, there was one place where it was intentional and necessary
*not* to flush the input buffer: pqReadData should never cause that to
happen, since we probably still want to process whatever data we read.

This is the true cause of the problem Robert was attempting to fix in
c3e7c24a1d60dc6a, namely that libpq no longer reported the backend's final
ERROR message before reporting "server closed the connection unexpectedly".
But that only accidentally fixed it, by invoking parseInput before the
input buffer got flushed; and very likely there are timing scenarios
where we'd still lose the message before processing it.

To fix, pass a flag to pqDropConnection to tell it whether to flush the
input buffer or not.  On review I think flushing is actually correct for
every other call site.

Back-patch to 9.3 where the problem was introduced.  In HEAD, also improve
the comments added by c3e7c24a1d60dc6a.

Branch
------
REL9_5_STABLE

Details
-------
http://git.postgresql.org/pg/commitdiff/747854f010b168c4f076cf44b61b100b0fe20866

Modified Files
--------------
src/interfaces/libpq/fe-connect.c   |   38 ++++++++++++++++++++---------------
src/interfaces/libpq/fe-misc.c      |    3 ++-
src/interfaces/libpq/fe-protocol3.c |    4 ++--
src/interfaces/libpq/libpq-int.h    |    2 +-
4 files changed, 27 insertions(+), 20 deletions(-)


-- 
Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-committers


^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* pgsql: Fix unwanted flushing of libpq's input buffer when socket EOF is
@ 2015-11-12 18:04  Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 4+ messages in thread

From: Tom Lane @ 2015-11-12 18:04 UTC (permalink / raw)
  To: pgsql-committers

Fix unwanted flushing of libpq's input buffer when socket EOF is seen.

In commit 210eb9b743c0645d I centralized libpq's logic for closing down
the backend communication socket, and made the new pqDropConnection
routine always reset the I/O buffers to empty.  Many of the call sites
previously had not had such code, and while that amounted to an oversight
in some cases, there was one place where it was intentional and necessary
*not* to flush the input buffer: pqReadData should never cause that to
happen, since we probably still want to process whatever data we read.

This is the true cause of the problem Robert was attempting to fix in
c3e7c24a1d60dc6a, namely that libpq no longer reported the backend's final
ERROR message before reporting "server closed the connection unexpectedly".
But that only accidentally fixed it, by invoking parseInput before the
input buffer got flushed; and very likely there are timing scenarios
where we'd still lose the message before processing it.

To fix, pass a flag to pqDropConnection to tell it whether to flush the
input buffer or not.  On review I think flushing is actually correct for
every other call site.

Back-patch to 9.3 where the problem was introduced.  In HEAD, also improve
the comments added by c3e7c24a1d60dc6a.

Branch
------
REL9_4_STABLE

Details
-------
http://git.postgresql.org/pg/commitdiff/40879a92b90cdd46f74588a2edb024a3c869d932

Modified Files
--------------
src/interfaces/libpq/fe-connect.c   |   38 ++++++++++++++++++++---------------
src/interfaces/libpq/fe-misc.c      |    3 ++-
src/interfaces/libpq/fe-protocol3.c |    4 ++--
src/interfaces/libpq/libpq-int.h    |    2 +-
4 files changed, 27 insertions(+), 20 deletions(-)


-- 
Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-committers


^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* pgsql: Fix unwanted flushing of libpq's input buffer when socket EOF is
@ 2015-11-12 18:04  Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 4+ messages in thread

From: Tom Lane @ 2015-11-12 18:04 UTC (permalink / raw)
  To: pgsql-committers

Fix unwanted flushing of libpq's input buffer when socket EOF is seen.

In commit 210eb9b743c0645d I centralized libpq's logic for closing down
the backend communication socket, and made the new pqDropConnection
routine always reset the I/O buffers to empty.  Many of the call sites
previously had not had such code, and while that amounted to an oversight
in some cases, there was one place where it was intentional and necessary
*not* to flush the input buffer: pqReadData should never cause that to
happen, since we probably still want to process whatever data we read.

This is the true cause of the problem Robert was attempting to fix in
c3e7c24a1d60dc6a, namely that libpq no longer reported the backend's final
ERROR message before reporting "server closed the connection unexpectedly".
But that only accidentally fixed it, by invoking parseInput before the
input buffer got flushed; and very likely there are timing scenarios
where we'd still lose the message before processing it.

To fix, pass a flag to pqDropConnection to tell it whether to flush the
input buffer or not.  On review I think flushing is actually correct for
every other call site.

Back-patch to 9.3 where the problem was introduced.  In HEAD, also improve
the comments added by c3e7c24a1d60dc6a.

Branch
------
REL9_3_STABLE

Details
-------
http://git.postgresql.org/pg/commitdiff/db6e8e1624a8f0357373450136c850f2b6e7fc8a

Modified Files
--------------
src/interfaces/libpq/fe-connect.c   |   38 ++++++++++++++++++++---------------
src/interfaces/libpq/fe-misc.c      |    3 ++-
src/interfaces/libpq/fe-protocol3.c |    4 ++--
src/interfaces/libpq/libpq-int.h    |    2 +-
4 files changed, 27 insertions(+), 20 deletions(-)


-- 
Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-committers


^ permalink  raw  reply  [nested|flat] 4+ messages in thread


end of thread, other threads:[~2015-11-12 18:04 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2015-11-12 18:04 pgsql: Fix unwanted flushing of libpq's input buffer when socket EOF is Tom Lane <tgl@sss.pgh.pa.us>
2015-11-12 18:04 pgsql: Fix unwanted flushing of libpq's input buffer when socket EOF is Tom Lane <tgl@sss.pgh.pa.us>
2015-11-12 18:04 pgsql: Fix unwanted flushing of libpq's input buffer when socket EOF is Tom Lane <tgl@sss.pgh.pa.us>
2015-11-12 18:04 pgsql: Fix unwanted flushing of libpq's input buffer when socket EOF is Tom Lane <tgl@sss.pgh.pa.us>

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