Hi Jingtang, Thank you for the patches. I tested v2 (0001 and 0002). They apply cleanly to master 5ffc82103773 and build without warnings.
I built with --enable-cassert --enable-tap-tests --enable-injection-points and used a small raw-protocol client that sends a query and never reads the reply. I set transaction_timeout to 2s. On master, without the patches: * A 300 MB result: the backend stays in ClientWrite long after 2s. * Andrey's case, COPY FROM STDIN left idle: the backend stays in ClientRead. * Zsolt's case: with 25 rows of 8000 bytes and then pg_sleep(6), the FATAL is logged but the backend stays in ClientWrite. A LOCK TABLE taken in that transaction stays held; another session gets "canceling statement due to lock timeout". With 20, 22, 23 or 24 rows the backend exits. With 26 to 32 rows it blocks in ClientWrite before the FATAL is logged, like the 300 MB case. So on my machine only 25 rows shows the FATAL logged and then the hang. * The same hang happens if pg_terminate_backend() is used instead of the timeout (at 25 rows). With 0001 only, the first two cases are fixed and the client gets the FATAL for COPY. The 25-row case, the SIGTERM variant and the held lock are not fixed, which matches your explanation. With 0001 and 0002, all of these exit, and the other session gets the lock. This also fits your plan to treat SIGTERM separately. Normal paths looked unchanged, on master and with the patches: * transaction_timeout with a reading client still delivers the FATAL message. * statement_timeout still gives an ERROR and the connection lives. * pg_terminate_backend() still delivers "terminating connection due to administrator command". * FATAL at startup (unknown database, unknown role) still reaches psql. make check passes (243 tests) on master and with both patches. test_misc passes with the patches (15 files, 257 tests), including the new tests in 005_timeouts.pl (5 tests, 2 on master). I saw no TRAP or PANIC in the server logs. >From these tests, the approach in 0002 looks reasonable to me. Two small questions from reading the code: 1. The comment in send_message_to_frontend() says parallel workers are excluded, but the check is only MyProcPort != NULL. Is that enough, or should the comment be reworded? 2. With the PqCommBusy check, socket_putmessage_noblock() drops the message silently. I think that is intended, since a nested message during a write was already suppressed. Is a short comment worth adding there? What I did not test: * The literal psql command from Zsolt's message (FETCH_COUNT=1 piped to sleep). On my master the backend exited, and I do not know why, so I used the raw client instead. * idle_in_transaction_session_timeout and an idle transaction with transaction_timeout. My client did not exercise them properly, so I only rely on the existing TAP tests. * 0002 without 0001, the extended protocol, COPY OUT, SSL or GSS, authentication, the libpq TAP tests, walsender, parallel workers, Windows, and backpatching. Thanks again for working on this. Best regards, Joao Rito
