Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit51ee561

Browse files
committed
Fix thinko in PQisBusy().
In commit1f39a1c I made PQisBusy consider conn->write_failed, butthat is now looking like complete brain fade. In the first place, thelogic is quite wrong: it ought to be like "and not" rather than "or".This meant that once we'd gotten into a write_failed state, PQisBusywould always return true, probably causing the calling application toiterate its loop until PQconsumeInput returns a hard failure thanksto connection loss. That's not what we want: the intended behavioris to return an error PGresult, which the application probably hasmuch cleaner support for.But in the second place, checking write_failed here seems like thewrong thing anyway. The idea of the write_failed mechanism is topostpone handling of a write failure until we've read all we can fromthe server; so that flag should not interfere with input-processingbehavior. (Compare7247e24.) What we *should* check for isstatus = CONNECTION_BAD, ie, socket already closed. (Most places thatclose the socket don't touch asyncStatus, but they do reset status.)This primarily ensures that if PQisBusy() returns true then there isan open socket, which is assumed by several call sites in our owncode, and probably other applications too.While at it, fix a nearby thinko in libpq's my_sock_write: we shouldonly consult errno for res < 0, not res == 0. This is harmless sincepqsecure_raw_write would force errno to zero in such a case, but itstill could confuse readers.Noted by Andres Freund. Backpatch to v12 where1f39a1c came in.Discussion:https://postgr.es/m/20220211011025.ek7exh6owpzjyudn@alap3.anarazel.de
1 parent0778b24 commit51ee561

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

‎src/interfaces/libpq/fe-exec.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1760,10 +1760,14 @@ PQisBusy(PGconn *conn)
17601760
parseInput(conn);
17611761

17621762
/*
1763-
* PQgetResult will return immediately in all states except BUSY, or if we
1764-
* had a write failure.
1763+
* PQgetResult will return immediately in all states except BUSY. Also,
1764+
* if we've detected read EOF and dropped the connection, we can expect
1765+
* that PQgetResult will fail immediately. Note that we do *not* check
1766+
* conn->write_failed here --- once that's become set, we know we have
1767+
* trouble, but we need to keep trying to read until we have a complete
1768+
* server message or detect read EOF.
17651769
*/
1766-
returnconn->asyncStatus==PGASYNC_BUSY||conn->write_failed;
1770+
returnconn->asyncStatus==PGASYNC_BUSY&&conn->status!=CONNECTION_BAD;
17671771
}
17681772

17691773

‎src/interfaces/libpq/fe-secure-openssl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1607,7 +1607,7 @@ my_sock_write(BIO *h, const char *buf, int size)
16071607

16081608
res=pqsecure_raw_write((PGconn*)BIO_get_data(h),buf,size);
16091609
BIO_clear_retry_flags(h);
1610-
if (res <=0)
1610+
if (res<0)
16111611
{
16121612
/* If we were interrupted, tell caller to retry */
16131613
switch (SOCK_ERRNO)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp