| From: | "Jelte Fennema-Nio" <postgres(at)jeltef(dot)nl> |
|---|---|
| To: | "Thomas Munro" <thomas(dot)munro(at)gmail(dot)com> |
| Cc: | "Bryan Green" <dbryan(dot)green(at)gmail(dot)com>, "Heikki Linnakangas" <hlinnaka(at)iki(dot)fi>, "pgsql-hackers" <pgsql-hackers(at)postgresql(dot)org>, "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>, "Kyotaro Horiguchi" <horikyota(dot)ntt(at)gmail(dot)com> |
| Subject: | Re: Can we get rid of TerminateThread() in pg_dump? |
| Date: | 2026-07-04 11:15:09 |
| Message-ID: | DJPQS3FYSD4U.3DBTXA6U8IQ0Q@jeltef.nl |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
On Sat, 4 Jul 2026 at 02:51, Thomas Munro <thomas(dot)munro(at)gmail(dot)com> wrote:
> We don't actually care about the threads
> themselves, and it doesn't seem that great if we have to introduce an
> IPC ping-pong of some kind with each thread.
Agreed. But I do agree with Heikki that swapping out stderr seems pretty
hacky. At the very least because now the main thread cannot write to
stderr either anymore (which is why you removed the "terminated by user"
write I guess).
How about instead we do something like the attached?
To be clear, I do think we should stop using TerminateThread because I
wanna replace PQcancel there with PQcancelBlocking[1] PQcancelBlocking
does a whole TLS handshake, which is almost certainly taking some locks.
Note that the way to achieve that I moved the Ctrl+C handler to a
dedicated thread on Unix too, so it starts behaving the same as Windows
in that respect. I think combined with you changing pg_dump to use
worker *threads* on Unix too, we would then get pretty much identical
behaviour across OSes for pg_dump.
P.S. I now realize that anything involving the (already existing)
CancelRequested flag is actually not actually safe/correct on Windows,
because it's not using read nor written using atomic operations while
the consoleHandler runs on its own thread. Would be good to fix that too
I guess, but it seems that for now it has worked in practice at least.
| Attachment | Content-Type | Size |
|---|---|---|
| v2-0001-Use-exit_nicely-in-die_on_query_failure.patch | text/x-patch | 1.1 KB |
| v2-0002-pg_dump-Remove-TerminateThread-call.patch | text/x-patch | 9.4 KB |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Dilip Kumar | 2026-07-04 13:06:56 | Re: Proposal: Conflict log history table for Logical Replication |
| Previous Message | Jim Jones | 2026-07-04 11:01:51 | Re: Truncate logs by max_log_size |