postgresql/src
Tom Lane 7247e243a8 Try to read data from the socket in pqSendSome's write_failed paths.
Even when we've concluded that we have a hard write failure on the
socket, we should continue to try to read data.  This gives us an
opportunity to collect any final error message that the backend might
have sent before closing the connection; moreover it is the job of
pqReadData not pqSendSome to close the socket once EOF is detected.

Due to an oversight in 1f39a1c06, pqSendSome failed to try to collect
data in the case where we'd already set write_failed.  The problem was
masked for ordinary query operations (which really only make one write
attempt anyway), but COPY to the server would continue to send data
indefinitely after a mid-COPY connection loss.

Hence, add pqReadData calls into the paths where pqSendSome drops data
because of write_failed.  If we've lost the connection, this will
eventually result in closing the socket and setting CONNECTION_BAD,
which will cause PQputline and siblings to report failure, allowing
the application to terminate the COPY sooner.  (Basically this restores
what happened before 1f39a1c06.)

There are related issues that this does not solve; for example, if the
backend sends an error but doesn't drop the connection, we did and
still will keep pumping COPY data as long as the application sends it.
Fixing that will require application-visible behavior changes though,
and anyway it's an ancient behavior that we've had few complaints about.
For now I'm just trying to fix the regression from 1f39a1c06.

Per a complaint from Andres Freund.  Back-patch into v12 where
1f39a1c06 came in.

Discussion: https://postgr.es/m/20200603201242.ofvm4jztpqytwfye@alap3.anarazel.de
2020-06-07 13:44:13 -04:00
..
backend Fix platform-specific performance regression in logtape.c. 2020-06-07 09:25:55 -07:00
bin Rethink definition of cancel.c's CancelRequested flag. 2020-06-07 13:07:34 -04:00
common Run pgindent with new pg_bsd_indent version 2.1.1. 2020-05-16 11:54:51 -04:00
fe_utils Rethink definition of cancel.c's CancelRequested flag. 2020-06-07 13:07:34 -04:00
include Spelling adjustments 2020-06-07 15:06:51 +02:00
interfaces Try to read data from the socket in pqSendSome's write_failed paths. 2020-06-07 13:44:13 -04:00
makefiles Remove libpq.rc, use win32ver.rc for libpq 2020-01-15 15:06:12 +01:00
pl Clear some style deviations. 2020-05-21 08:31:16 -07:00
port Clear some style deviations. 2020-05-21 08:31:16 -07:00
template Fix compiler warning for ppoll() on Cygwin 2019-12-22 23:20:00 +01:00
test Spelling adjustments 2020-06-07 15:06:51 +02:00
timezone Run pgindent with new pg_bsd_indent version 2.1.1. 2020-05-16 11:54:51 -04:00
tools Refresh function name in CRC-associated Valgrind suppressions. 2020-06-05 20:10:53 -07:00
tutorial Update copyrights for 2020 2020-01-01 12:21:45 -05:00
.gitignore
DEVELOPERS
Makefile
Makefile.global.in Update Unicode data to Unicode 13.0.0 and CLDR 37 2020-04-24 09:52:59 +02:00
Makefile.shlib Add PostgreSQL home page to --help output 2020-02-28 13:12:21 +01:00
nls-global.mk