public inbox for [email protected]
help / color / mirror / Atom feedFrom: Tatsuo Ishii <[email protected]>
To: [email protected]
Subject: pgpool: Fix COPY IN hang in extended query mode.
Date: Sun, 07 Jun 2026 10:10:55 +0000
Message-ID: <[email protected]> (raw)
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 <[email protected]>
Discussion: https://github.com/pgpool/pgpool2/issues/162
Backpatch-through: v4.3
Branch
------
master
Details
-------
https://git.postgresql.org/gitweb?p=pgpool2.git;a=commitdiff;h=23363900b1f8d17fd22a5daa7576d37a0e20c...
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/126.copy_hang/copy-in-expected | 31 ++++++++++++
.../tests/126.copy_hang/pgproto-copy-in.data | 15 ++++++
src/test/regression/tests/126.copy_hang/test.sh | 9 ++++
7 files changed, 162 insertions(+), 7 deletions(-)
view thread (6+ messages)
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected], [email protected]
Subject: Re: pgpool: Fix COPY IN hang in extended query mode.
In-Reply-To: <[email protected]>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox