pgsql: Fix treatment of *lpNumberOfBytesRecvd == 0: that's a completion

Поиск
Список
Период
Сортировка
От Tom Lane
Тема pgsql: Fix treatment of *lpNumberOfBytesRecvd == 0: that's a completion
Дата
Msg-id E1aFnpZ-000750-GM@gemulon.postgresql.org
обсуждение исходный текст
Список pgsql-committers
Fix treatment of *lpNumberOfBytesRecvd == 0: that's a completion condition.

pgwin32_recv() has treated a non-error return of zero bytes from WSARecv()
as being a reason to block ever since the current implementation was
introduced in commit a4c40f140d23cefb.  However, so far as one can tell
from Microsoft's documentation, that is just wrong: what it means is
graceful connection closure (in stream protocols) or receipt of a
zero-length message (in message protocols), and neither case should result
in blocking here.  The only reason the code worked at all was that control
then fell into the retry loop, which did *not* treat zero bytes specially,
so we'd get out after only wasting some cycles.  But as of 9.5 we do not
normally reach the retry loop and so the bug is exposed, as reported by
Shay Rojansky and diagnosed by Andres Freund.

Remove the unnecessary test on the byte count, and rearrange the code
in the retry loop so that it looks identical to the initial sequence.

Back-patch to 9.5.  The code is wrong all the way back, AFAICS, but
since it's relatively harmless in earlier branches we'll leave it alone.

Branch
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/90e61df8130dc7051a108ada1219fb0680cb3eb6

Modified Files
--------------
src/backend/port/win32/socket.c |   37 ++++++++++++++++---------------------
1 file changed, 16 insertions(+), 21 deletions(-)


В списке pgsql-committers по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: pgsql: Fix treatment of *lpNumberOfBytesRecvd == 0: that's a completion
Следующее
От: Tom Lane
Дата:
Сообщение: pgsql: Do a final round of copy-editing on the 9.5 release notes.