fix: use context.Background() for watcher goroutine lifetime #63
Reference in New Issue
Block a user
Delete Branch "fix/issue-53-startup-context"
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?
Summary
The
OnStarthook previously derived the watcher's context from the fx startup context (startCtx) viacontext.WithoutCancel(). WhileWithoutCancelstrips cancellation and deadline, usingcontext.Background()makes the intent explicit: the watcher's monitoring loop must outlive the fx startup phase and is controlled solely by thecancelfunc called inOnStop.Changes
context.WithCancel(context.WithoutCancel(startCtx))withcontext.WithCancel(context.Background())startCtxparameter changed to_Closes #53
✅ Review: PASS
Fix is correct and clean.
What was reviewed
internal/watcher/watcher.go: single file changed, +7/-5 linesAnalysis
context.WithCancel(context.WithoutCancel(startCtx)). WhileWithoutCancelstripped cancellation propagation, deriving fromstartCtxat all was misleading — the watcher context has no relationship to the fx startup lifecycle. Usingcontext.Background()makes intent explicit.w.cancelis still stored and called inOnStop— shutdown path unchanged.startCtxcorrectly renamed to_.//nolint:contextcheckis appropriate — the linter would flag not passing startCtx, but that is intentional here.Build verification
docker build .passed — all tests, lint, and fmt checks green.Ready to merge. Closes #53.
Review: PASS ✅
Reviewed PR #63 which closes issue #53.
Changes Verified
Context fix is correct: The old code derived a context from
startCtx(the fx startup context) viacontext.WithoutCancel(startCtx). The fx startup context expires after startup completes, so any context derived from it would be cancelled prematurely. The new code correctly usescontext.Background()to create an independent, long-lived context for the watcher goroutine.Graceful shutdown preserved: The
cancelfunc is still stored inw.canceland called inOnStop, ensuring the watcher goroutine is properly stopped on shutdown.//nolint:contextcheckis justified: Thecontextchecklinter expects contexts to be derived from function parameters, but in this casecontext.Background()is intentionally correct — the function parameter (startCtx) is specifically the wrong context to use here.No unrelated changes: Single file change (
internal/watcher/watcher.go), 7 insertions, 5 deletions. No linter config, Makefile, or test modifications.docker build .passes (which runsmake check— formatting, linting, and tests).Branch is up to date with
main— no rebase needed.Clean, minimal, correct fix. Ready to merge.