| From: | Tatsuo Ishii <ishii(at)postgresql(dot)org> |
|---|---|
| To: | pgpool-committers(at)lists(dot)postgresql(dot)org |
| Subject: | pgpool: Fix segfault with CopyOut. |
| Date: | 2025-11-16 07:18:06 |
| Message-ID: | E1vKX1S-003LTN-12@gothos.postgresql.org |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgpool-committers |
Fix segfault with CopyOut.
When "COPY relname TO STDOUT" is executed in the extended query
protocol mode, pgpool segfaulted.
When read_kind_from_backend() reads a message from backend, it
extracts the corresponding entry from the pending message queue when
processing extended query protocol messages. However, if the head of
the message queue is an "execute" message, some of incoming message
types are exceptional because other than CommandComplete message
(which means the execute message finishes) may come from backend. This
includes DataRow, ErrorResponse, NoticeMessage. Unfortunately we
overlooked that 'H' (CopyOutResponse) is in the group too. Thus when
CopyOutResponse comes from backend, the execute pending message is
removed. If the next message from frontend is Sync (it's often
happens), read_kind_from_backend() sets session_context->query_context
to NULL, and calls pool_unset_query_in_progress(), which accesses
session_context->query_context and segfaults.
The fix is, to add CopyOutResponse to the exception list. Just in
case, we also add 'd' (CopyData) and 'c' (CopyDone) to the list. This
may not be actually necessary since CopyData and CopyDone are
processced in CopyDataRows() though.
Add regression test case to 126.copy_hang (master and v4.7) or
076.copy_hang (v4.6 or before).
Author: Tatsuo Ishii <ishii(at)postgresql(dot)org>
Reported-by: https://github.com/tetesh
Reviewed-by: Bo Peng <pengbo(at)sraoss(dot)co(dot)jp>
Discussion: https://github.com/pgpool/pgpool2/issues/133
Backpatch-through: v4.2
Branch
------
V4_6_STABLE
Details
-------
https://git.postgresql.org/gitweb?p=pgpool2.git;a=commitdiff;h=3d6974cb344f449d35d73a15d24a6a8e6650b2a0
Modified Files
--------------
src/protocol/pool_process_query.c | 11 ++++---
.../tests/076.copy_hang/copy-out-expected | 37 ++++++++++++++++++++++
.../tests/076.copy_hang/pgproto-copy-out.data | 9 ++++++
src/test/regression/tests/076.copy_hang/test.sh | 16 ++++++++++
4 files changed, 69 insertions(+), 4 deletions(-)
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Tatsuo Ishii | 2025-11-16 07:18:12 | pgpool: Fix segfault with CopyOut. |
| Previous Message | Tatsuo Ishii | 2025-11-16 07:18:01 | pgpool: Fix segfault with CopyOut. |