Skip to content

fix(dapi): use signal.NotifyContext for graceful shutdown#969

Open
Mayveskii wants to merge 1 commit intogonka-ai:mainfrom
Mayveskii:fix/graceful-shutdown-signal-context
Open

fix(dapi): use signal.NotifyContext for graceful shutdown#969
Mayveskii wants to merge 1 commit intogonka-ai:mainfrom
Mayveskii:fix/graceful-shutdown-signal-context

Conversation

@Mayveskii
Copy link
Copy Markdown

Problem

Root context uses context.WithCancel which SIGTERM does not cancel. Config flush never runs on docker stop.

Fix

Replace with signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM) so SIGTERM/SIGINT propagate through context tree.

Impact: config reliably flushed on shutdown, zero change on happy path

@akup
Copy link
Copy Markdown
Collaborator

akup commented Apr 1, 2026

Tiny useful fix. Please rebase

The root context was created with context.WithCancel(context.Background())
which is only cancelled when cancel() is called explicitly (i.e. on
normal function return). Sending SIGTERM (e.g. docker stop, systemctl stop)
killed the process immediately via SIGKILL after timeout, bypassing the
deferred config flush and other cleanup.

Replace with signal.NotifyContext so SIGTERM/SIGINT propagate through
the context tree: all goroutines using ctx observe cancellation and
shut down cleanly, and the config flush at <-ctx.Done() actually runs.
@Mayveskii Mayveskii force-pushed the fix/graceful-shutdown-signal-context branch from 3dec289 to 8c00fa3 Compare April 4, 2026 05:42
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.

2 participants