forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit0214a61
committed
Fix potential deadlock with libpq non-blocking mode.
If libpq output buffer is full, pqSendSome() function tries to drain anyincoming data. This avoids deadlock, if the server e.g. sends a lot ofNOTICE messages, and blocks until we read them. However, pqSendSome() onlydid that in blocking mode. In non-blocking mode, the deadlock could stillhappen.To fix, take a two-pronged approach:1. Change the documentation to instruct that when PQflush() returns 1, youshould wait for both read- and write-ready, and call PQconsumeInput() if itbecomes read-ready. That fixes the deadlock, but applications are not goingto change overnight.2. In pqSendSome(), drain the input buffer before returning 1. Thisalleviates the problem for applications that only wait for write-ready. Inparticular, a slow but steady stream of NOTICE messages during COPY FROMSTDIN will no longer cause a deadlock. The risk remains that the serverattempts to send a large burst of data and fills its output buffer, and atthe same time the client also sends enough data to fill its output buffer.The application will deadlock if it goes to sleep, waiting for the socketto become write-ready, before the server's data arrives. In practice,NOTICE messages and such that the server might be sending are usuallyshort, so it's highly unlikely that the server would fill its output bufferso quickly.Backpatch to all supported versions.1 parent9c15a77 commit0214a61
2 files changed
+25
-11
lines changedLines changed: 8 additions & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
4380 | 4380 |
| |
4381 | 4381 |
| |
4382 | 4382 |
| |
4383 |
| - | |
| 4383 | + | |
| 4384 | + | |
| 4385 | + | |
| 4386 | + | |
| 4387 | + | |
| 4388 | + | |
| 4389 | + | |
| 4390 | + | |
4384 | 4391 |
| |
4385 | 4392 |
| |
4386 | 4393 |
| |
|
Lines changed: 17 additions & 10 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
904 | 904 |
| |
905 | 905 |
| |
906 | 906 |
| |
907 |
| - | |
908 |
| - | |
909 |
| - | |
910 |
| - | |
911 |
| - | |
912 |
| - | |
913 |
| - | |
914 |
| - | |
915 |
| - | |
916 |
| - | |
917 | 907 |
| |
918 | 908 |
| |
919 | 909 |
| |
| |||
924 | 914 |
| |
925 | 915 |
| |
926 | 916 |
| |
| 917 | + | |
| 918 | + | |
| 919 | + | |
| 920 | + | |
| 921 | + | |
| 922 | + | |
| 923 | + | |
| 924 | + | |
| 925 | + | |
| 926 | + | |
927 | 927 |
| |
928 | 928 |
| |
929 | 929 |
| |
930 | 930 |
| |
931 | 931 |
| |
932 | 932 |
| |
| 933 | + | |
| 934 | + | |
| 935 | + | |
| 936 | + | |
| 937 | + | |
| 938 | + | |
| 939 | + | |
933 | 940 |
| |
934 | 941 |
| |
935 | 942 |
| |
|
0 commit comments
Comments
(0)