diff --git a/src/backend/libpq/pqcomm.c b/src/backend/libpq/pqcomm.c index cd517e8bb4..fcd8ee8047 100644 --- a/src/backend/libpq/pqcomm.c +++ b/src/backend/libpq/pqcomm.c @@ -288,6 +288,17 @@ socket_close(int code, Datum arg) */ secure_close(MyProcPort); +#ifdef WIN32 + /* + * On Windows, the client end of the socket won't be able to read the + * data once we close the socket. So, give clients some time to read + * the pending data especially in failure cases before we can close + * the socket. + */ + if (code != 0) + pg_usleep(1000000L); +#endif + /* * Formerly we did an explicit close() here, but it seems better to * leave the socket open until the process dies. This allows clients