Skip to content

Fix: SIGINT was ignored by the cln docker container#9315

Merged
daywalker90 merged 1 commit into
ElementsProject:masterfrom
btcpayserver:trap-docker
Jul 20, 2026
Merged

Fix: SIGINT was ignored by the cln docker container#9315
daywalker90 merged 1 commit into
ElementsProject:masterfrom
btcpayserver:trap-docker

Conversation

@NicolasDorier

@NicolasDorier NicolasDorier commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Changelog-Fixed: Fix: SIGINT was ignored by the cln docker container

This was reported by one of our user.

I could replicate with

docker kill --signal=SIGINT <container>

I confirm that now both, with and without --signal=SIGINT works properly.

The file to fix is tools/docker-entrypoint.sh (the Dockerfile copies it to /entrypoint.sh at lines 245 and 278 for the two image stages — the Dockerfile itself is fine).

The bug lives in three lines of that script:

  • Lines 64–65: set -m + lightningd "$@" & — lightningd is started as a background job in its own process group, so it will never see signals sent to PID 1.
  • Line 122 (last line): fg %- — bash re-foregrounds lightningd and blocks there as PID 1 with no trap. A PID 1 with no handler installed never receives SIGTERM at all, so docker stop does nothing until the grace-period expires and the container is SIGKILLed — exit 137 on every shutdown, and lightningd never closes its database cleanly.

The fix — replace line 122's fg %- with:

trap 'kill -TERM "$LIGHTNINGD_PID" 2>/dev/null' TERM INT
wait "$LIGHTNINGD_PID"
trap - TERM INT
wait "$LIGHTNINGD_PID"
exit $?

Why this shape and not just adding a trap above fg: bash defers trap execution while a foreground job is running, so a trap combined with fg would only fire after lightningd already exited. wait, by contrast, is interrupted by trapped signals — the first wait returns when SIGTERM arrives and the trap forwards it to lightningd, the second wait collects lightningd's actual exit status.

@NicolasDorier
NicolasDorier marked this pull request as ready for review July 15, 2026 01:55
cdecker
cdecker previously approved these changes Jul 19, 2026
Comment thread tools/docker-entrypoint.sh Outdated
Changelog-Fixed: Fix: SIGINT was ignored by the cln docker container
@daywalker90
daywalker90 enabled auto-merge (rebase) July 20, 2026 15:17
@daywalker90
daywalker90 merged commit 02e06fc into ElementsProject:master Jul 20, 2026
83 of 88 checks passed
@NicolasDorier
NicolasDorier deleted the trap-docker branch July 21, 2026 00:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants