| From: | Thomas Munro <thomas(dot)munro(at)gmail(dot)com> |
|---|---|
| To: | Bryan Green <dbryan(dot)green(at)gmail(dot)com> |
| Cc: | 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 00:51:08 |
| Message-ID: | CA+hUKGL0ZeiO0ND+ksAi5inRY98GEGtyM4t8CVhF1mZaAqYjVA@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
On Sat, Jul 4, 2026 at 3:36 AM Bryan Green <dbryan(dot)green(at)gmail(dot)com> wrote:
> On 7/3/2026 10:05 AM, Heikki Linnakangas wrote:
> >> Apparently this hasn't been a problem in practice. Error reporting
> >> coinciding with ^C must be unlikely? I'd still like to find a
> >> non-evil way to suppress log output, though. What if we atomically
> >> pointed STDERR_FILENO to /dev/null, with dup2()? I wrote a patch to
> >> try that idea out, but I don't have Windows, so I'm sharing this as a
> >> curiosity in case anyone wants to try it and/or comment on all this.
> >> Or has a better idea. Preferably that would work on Windows and Unix
> >> (if it also used threads).
> >
> > Huh, that's pretty hacky. I think we should adopt our usual signal
> > handling approach here: Instead of calling PQcancel() from the signal
> > handler (or consoleHandler()), just set a global flag, wake up the main
> > thread, and perform the cancellation from the main thread. In the worker
> > threads, you can refrain from printing the cancellation error if the
> > flag is set.
> >
> > Dunno how complicated that is to change..
> The main thread is waiting at the select()...waking that from a
> different thread is going to be doable but awkward in the current
> implementation on Windows (pipe and sockets).
I agree that, in general, cooperative/flag based interruption is the
right architecture and standard approach, and I did think a bit about
how to make that work, but I couldn't figure out how to do it without
introducing extra waits. You'd have to ask each thread to shut down
and wait for it to acknowledge your request, but this is supposed to
be a fast shutdown, and abnormal termination. We're subseconds away
from _exit() nuking everything, and we really just want to tell the
*server* to cancel whatever it's doing so we don't leave a long CREATE
INDEX or whatever running. 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. With this approach we
don't have to, we just disconnect them from stderr slightly before the
kernel vaporises them. Doesn't seem that bad to me?
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Nico Williams | 2026-07-04 01:00:49 | Re: Global temporary tables |
| Previous Message | Thomas Munro | 2026-07-04 00:38:53 | Re: Can we get rid of TerminateThread() in pg_dump? |