forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit335fa5a
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.de1 parent52377bb commit335fa5a
2 files changed
+8
-4
lines changedLines changed: 7 additions & 3 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1957 | 1957 |
| |
1958 | 1958 |
| |
1959 | 1959 |
| |
1960 |
| - | |
1961 |
| - | |
| 1960 | + | |
| 1961 | + | |
| 1962 | + | |
| 1963 | + | |
| 1964 | + | |
| 1965 | + | |
1962 | 1966 |
| |
1963 |
| - | |
| 1967 | + | |
1964 | 1968 |
| |
1965 | 1969 |
| |
1966 | 1970 |
| |
|
Lines changed: 1 addition & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1682 | 1682 |
| |
1683 | 1683 |
| |
1684 | 1684 |
| |
1685 |
| - | |
| 1685 | + | |
1686 | 1686 |
| |
1687 | 1687 |
| |
1688 | 1688 |
| |
|
0 commit comments
Comments
(0)