Fix hang after a flush message received.
authorTatsuo Ishii <ishii@postgresql.org>
Tue, 30 Jul 2024 09:17:57 +0000 (18:17 +0900)
committerTatsuo Ishii <ishii@postgresql.org>
Tue, 30 Jul 2024 09:30:43 +0000 (18:30 +0900)
Previously pgpool could hang after a flush message arrives. Consider
following scenario:

(1) backend sends a portal suspend message.
(2) pgool write it in the frontend write buffer. But not flush it.
(3) The frontend sends a flush message to pgpool.
(4) pgpool fowards the flush message to backend.
(5) Since there's no pending message in backend, nothing happen.
(6) The frontend waits for the portal suspend message from pgpool in vain.

To fix this, at (4) pgpool flushes data in the frontend write buffer
if some data remains (in this case the portal suspend message). Then
the frontend will send next request message to pgpool.

Discussion: https://github.com/pgpool/pgpool2/issues/59
Backpatch-through: master, 4.5, 4.4, 4.3, 4.2 and 4.1.

src/protocol/pool_proto_modules.c

index a17b5bafb20451b0f3dc1ce5b46e5ba5ce7ee723..b4c4018ea6a9316d91cd9e6501ea4560965f9db3 100644 (file)
@@ -2887,6 +2887,13 @@ ProcessFrontendResponse(POOL_CONNECTION * frontend,
                        {
                                if (fkind == 'H')
                                {
+                                       /*
+                                        * If data remains in the frontend write buffer, flush it
+                                        * now.
+                                        */
+                                       pool_flush(frontend);
+                                       elog(DEBUG5,
+                                                "pending data flushed to frontend due to a flush message");
                                        pool_set_doing_extended_query_message();
                                }
                                status = SimpleForwardToBackend(fkind, frontend, backend, len, contents);