| From: | Tatsuo Ishii <ishii(at)postgresql(dot)org> |
|---|---|
| To: | pgpool-committers(at)lists(dot)postgresql(dot)org |
| Subject: | pgpool: Fix COPY IN hang in extended query mode. |
| Date: | 2026-06-07 10:10:27 |
| Message-ID: | E1wWASZ-009eDb-1R@gothos.postgresql.org |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgpool-committers |
Fix COPY IN hang in extended query mode.
If COPY FROM STDIN is executed in extended query mode in streaming
replication mode, pgpool hung in CopyDataRow(). Consider following
scenario:
FE=> Parse(stmt="", query="COPY t1 FROM STDIN")
FE=> Bind(stmt="", portal="")
FE=> Execute(portal="")
FE=> CopyData (copy data="1
")
FE=> CopyData (copy data="2
")
FE=> CopyDone
FE=> Sync
<= BE ParseComplete
<= BE BindComplete
<= BE CopyInResponse
The backend responses with ParseComplete, BindComplete and
CopyInResponse, exepecting CopyData coming from pgpool. However, as
frontend sent CopyData before CopyInResponse coming from the backend,
the backend ignores tha CopData. Moreover, CopyDataRow has no chance
to forward Sync message to the backend, and the backend does not
respond with CommandComplete but CopyDataRow waited for it in vain,
causes a hang.
To fix the problems, add suspend_reading_from_frontend_copy_in flag to
the session context. The flag is set within Execute() to prevent
reading messages from frontend until COPY IN response comes from the
backend. After it arrives, CopyDataRow is called and process CopyData
until frontend sends CopyDone messages. CopyDataRow forwards it to the
backend, then reset query in progress flag and return. This will cause
pool_process_query's main loop to read Sync message from frontend, and
pgpool forwards it to the backend. After that CommandComplete and
ReadyForQuery arrives from the backend as expected.
Test case added to 126.copy_hang.
Reported-by: liujinyang-highgo
Reviewed-by: liujinyang-highgo
Author: Tatsuo Ishii <ishii(at)postgresql(dot)org>
Discussion: https://github.com/pgpool/pgpool2/issues/162
Backpatch-through: v4.3
Branch
------
V4_3_STABLE
Details
-------
https://git.postgresql.org/gitweb?p=pgpool2.git;a=commitdiff;h=6171c6156f3ceb7276152542f1693b6b42586b52
Modified Files
--------------
src/context/pool_session_context.c | 30 +++++++++++
src/include/context/pool_session_context.h | 11 ++++
src/protocol/pool_process_query.c | 14 ++---
src/protocol/pool_proto_modules.c | 59 +++++++++++++++++++++-
.../tests/076.copy_hang/copy-in-expected | 31 ++++++++++++
.../tests/076.copy_hang/pgproto-copy-in.data | 15 ++++++
src/test/regression/tests/076.copy_hang/test.sh | 9 ++++
7 files changed, 162 insertions(+), 7 deletions(-)
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Tatsuo Ishii | 2026-06-07 10:10:33 | pgpool: Fix COPY IN hang in extended query mode. |
| Previous Message | Tatsuo Ishii | 2026-06-07 03:12:37 | pgpool: Prevent pcp_node_info from hanging. |