Handle SIGTERM in fe_utils/cancel.c

Started by Tristan Partinover 3 years ago3 messageshackers
Beta feature

Hackorum builds and tests every patch posted to the lists, not only commitfest submissions. This is Hackorum's own CI rather than the PostgreSQL project's, and it is still under testing - please report anything that looks wrong.

appliessuccessCI history

You can run a PostgreSQL built from this patch straight from Docker, with no checkout and no build:

docker run --rm -p 5432:5432 ghcr.io/hackorum-dev/postgres-patch:t47885
psql -h localhost -U postgres

Built from patchset v1 (message #1), September 20, 2026 at 05:18 AM.

Every patchset is also pushed to a branch of our PostgreSQL fork, so you can check out the same tree CI built. Without a PostgreSQL checkout:

git clone --branch t47885_1 https://github.com/hackorum-dev/postgres.git

In a checkout you already have, add the fork once:

git remote add hackorum https://github.com/hackorum-dev/postgres.git

then, for this patchset and every later one:

git fetch hackorum t47885_1 && git checkout t47885_1

Patchset v1 (message #1) is on t47885_1

Jump to latest
#1Tristan Partin
tristan@neon.tech

Hello,

This is a way that would solve bug #17698[1]/messages/by-id/17698-58a6ab8caec496b0@postgresql.org. It just reuses the same
handler as SIGINT (with a function rename).

This patch works best if it is combined with my previous submission[2]/messages/by-id/CSSWBAX56CVY.291H6ZNNHK7EO@c3po.
I can rebase that submission if and when this patch is pulled in.

[1]: /messages/by-id/17698-58a6ab8caec496b0@postgresql.org
[2]: /messages/by-id/CSSWBAX56CVY.291H6ZNNHK7EO@c3po

--
Tristan Partin
Neon (https://neon.tech)

Attachments:

t47885_1
v1-0001-Handle-SIGTERM-in-fe_utils-cancel.c.patchtext/x-patch; charset=utf-8; name=v1-0001-Handle-SIGTERM-in-fe_utils-cancel.c.patchDownload+4-5
#2Michael Paquier
michael@paquier.xyz
In reply to: Tristan Partin (#1)
Re: Handle SIGTERM in fe_utils/cancel.c

On Mon, May 22, 2023 at 12:26:34PM -0500, Tristan Partin wrote:

This is a way that would solve bug #17698[1]. It just reuses the same
handler as SIGINT (with a function rename).

This patch works best if it is combined with my previous submission[2].
I can rebase that submission if and when this patch is pulled in.

Not sure that this is a good idea long-term. Currently, the code
paths calling setup_cancel_handler() from cancel.c don't have a custom
handling for SIGTERM, but that may not be the case forever.
--
Michael

#3Tristan Partin
tristan@neon.tech
In reply to: Michael Paquier (#2)
Re: Handle SIGTERM in fe_utils/cancel.c

On Tue May 23, 2023 at 7:51 PM CDT, Michael Paquier wrote:

On Mon, May 22, 2023 at 12:26:34PM -0500, Tristan Partin wrote:

This is a way that would solve bug #17698[1]. It just reuses the same
handler as SIGINT (with a function rename).

This patch works best if it is combined with my previous submission[2].
I can rebase that submission if and when this patch is pulled in.

Not sure that this is a good idea long-term. Currently, the code
paths calling setup_cancel_handler() from cancel.c don't have a custom
handling for SIGTERM, but that may not be the case forever.

I am more than happy to essentially just copy & paste some code that
will be specific to pgbench if that is preferrable for the purposes of
merging this patch. Another idea would be to change the signature of
setup_cancel_handler() to something like:

void
setup_cancel_handler(cb pre, cb post, int signal, ...); (null-terminate)

Then a client could state exactly what signals it wants to register with
this generic cancel handler.

--
Tristan Partin
Neon (https://neon.tech)