| From: | Jingtang Zhang <mrdrivingduck(at)gmail(dot)com> |
|---|---|
| To: | Andrey Borodin <x4mmm(at)yandex-team(dot)ru>, Zsolt Parragi <zsolt(dot)parragi(at)percona(dot)com> |
| Cc: | pgsql-hackers mailing list <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Alexander Korotkov <aekorotkov(at)gmail(dot)com>, 邱宇航 <iamqyh(at)gmail(dot)com> |
| Subject: | Re: transaction_timeout is not enforced during ClientWrite |
| Date: | 2026-11-16 06:36:07 |
| Message-ID: | CAPsk3_AZOjx-_HFxLm+7xcLU7ysERiF2hVBENjnKain=TAZGbw@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
Hi,
Thanks for the feedback.
> During COPY input, DoingCommandRead is false. The read-wait path in
> ProcessClientReadInterrupt() then handles ProcDiePending, but not
> TransactionTimeoutPending. Could the fix cover this path too?
Thanks, Andrey.
Yes. I initially thought the DoingCommandRead branch already covered
ClientRead. I reproduced the issue by leaving COPY FROM STDIN waiting
for input past the transaction timeout. It looks like the same approach
as for ClientWrite should work in ProcessClientReadInterrupt().
I've attached v2 with that change.
> It works if the timer fires while the backend is already blocked in
> the write, but if the client has already stopped reading and the timer
> fires while the backend is still doing something else,
> ProcessInterrupts() clears TransactionTimeoutPending and raises the
> FATAL, then pq_flush() blocks. At that point nothing is pending for
> ProcessClientWriteInterrupt() to act on, so we wait forever, and the
> transaction is only aborted later in proc_exit().
Thanks, Zsolt.
Oh, yes, I see what you mean. But I think this goes a bit beyond
transaction_timeout. The same thing can happen with SIGTERM when
ProcessInterrupts() handles ProcDiePending. So I plan to address
this in a separate patch in v2.
Once the backend has decided to terminate the connection, sending
the error to the client should be best-effort. The patch changes
send_message_to_frontend() to send FATAL reports to client sockets
without waiting for the socket to become writable. That lets the
backend exit after either a transaction timeout or SIGTERM, even
if the client has stopped reading.
Does that approach sound reasonable?
I've attached v2 as two separate patches.
---
Regards,
Jingtang
| Attachment | Content-Type | Size |
|---|---|---|
| v2-0001-Honor-transaction-timeout-during-blocked-client-reads-and-writes.patch | application/octet-stream | 5.5 KB |
| v2-0002-Avoid-blocking-on-client-output-when-reporting-FATAL-errors.patch | application/octet-stream | 3.9 KB |
| From | Date | Subject | |
|---|---|---|---|
| Previous Message | Fujii Masao | 2026-11-16 06:19:02 | Re: 041_checkpoint_at_promote.pl might fail due to race condition on child kill |