[pgpool-committers: 6851] pgpool: Fix pgpool hang in a corner case.

Tatsuo Ishii ishii at sraoss.co.jp
Thu Jul 9 09:40:02 JST 2020


Fix pgpool hang in a corner case.

It is possible that an "out of band" message from backend has been
read into buffer at the time when a ready for query message is
processed. If the messages are from all backends, there should be no
problem because ProcessBackendResponse() will read the messages from
all backends by using read_kind_from_backend(). However there could be
a corner case: 1) If the message is coming from only one of backend
(this could happen when recovery conflict or backend receiving SIGTERM
and so on) and 2) the message is already in the backend read
buffer. In this case pgpool will hang in pool_read() called by
read_kind_from_backend() at either: 1)
read_kind_from_one_backend(frontend, backend, (char *) &kind,
MASTER_NODE_ID) (the message is not coming from master backend) or 2)
pool_read(CONNECTION(backend, i), &kind, 1) (the message is not coming
from other than master).

Note If the message is not in the buffer, there should be no problem
since read_packets_and_process() will take care that "out of band"
messages.

The solution is, read and discard such a message in ReadyforQuery(),
emitting log to make sure that the read buffer is empty after
returning from ReadyForQuery(). (remember that unless the ready for
query message is returned to frontend, the frontend will not issue
next query and there's should be no response from backend except the
out of band messages).

If the message was FATAL, the backend will disconnect to pgpool. So
next time pgpool should notice that the connection is closed anyway.

For the master branch, probably we should treat that kind of FATAL
message in a same way as read_packets_and_process() already does. This
requires some code refactoring and I would like to leave the job
separated from this commit.

Branch
------
V4_0_STABLE

Details
-------
https://git.postgresql.org/gitweb?p=pgpool2.git;a=commitdiff;h=69ae44f1476cc430e08f8e7d0918ff082ec4df31

Modified Files
--------------
src/protocol/pool_proto_modules.c | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)



More information about the pgpool-committers mailing list