Shutdown correctness: exit code always 0, two competing signal handlers, Sentry calls os.Exit from a goroutine #86
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Verified against
mainat61f42e6.Three related defects in process lifecycle:
1. The computed exit code is discarded.
internal/server/server.go:110-130—serve()computes and returns an exit code;Run()(:86-89) throws it away.pixadtherefore exits 0 even when it shut down because of an error. Any supervisor (systemd, uPaaS per #17, Docker restart policies, CI) that keys off exit status sees a clean exit from a crash, so a failing daemon reads as a deliberate stop and may not be restarted or alerted on.2. Two independent signal handlers.
fx.Run()(cmd/pixad/main.go:59) installs its own SIGINT/SIGTERM handling, andserver.serveinstalls a second atinternal/server/server.go:113-122. Both fire on the same signal. Two shutdown paths racing on one signal is how "sometimes it hangs on stop" and "sometimes it exits before flushing" bugs are born, and neither is reproducible on demand.3. Sentry initialization calls
os.Exit(1)from a goroutine (server.go:104), bypassing fx's lifecycle entirely — noOnStophooks run, so the database and any in-flight work are abandoned rather than closed.Related, and worth resolving in the same pass:
cleanShutdown(server.go:132-146) has a 5 s timeout but does not wait for in-flight libvips work. With #55 this also interacts withStopEviction, which blocks with no timeout while a reconciliation pass finishes — see thecontextcheckdecision recorded on PR #54.Definition of done
serve()reachesos.Exit; a shutdown caused by an error exits non-zero, a clean signal-triggered shutdown exits 0.os.Exitfrom a goroutine, so lifecycle hooks run.cleanShutdownwaits for in-flight image processing, bounded by its timeout; on timeout it logs what was still outstanding rather than exiting silently.main; signal handling generally is not, so state explicitly in the PR what was verified manually.make checkgreen.Coordination
Point 4 overlaps the eviction-loop cancellability decision flagged on PR #54. Do this after both open PRs land, and resolve the two together — they are the same question about who owns shutdown.