Wait for final log flush before closing deploymentLogWriter (closes #4) #9
No reviewers
Labels
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: sneak/upaas#9
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch ":fix/issue-4"
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?
Review: PR#9 — Wait for final log flush before closing deploymentLogWriter
Overall: Excellent fix. Small, precise, and addresses a real race condition.
Positives
sync.WaitGroupidiomatically to coordinate the flush goroutine lifecycle.defer w.flushed.Done()inrunFlushLoopensures Done is called even if the loop exits unexpectedly.Observations
runFlushLooppanics: If the goroutine panics beforeDone(),Close()would block forever. Thedeferplacement mitigates this for normal exits, but a recovered panic in the flush logic could still leave the WaitGroup hanging. Very unlikely in practice.flushed.Wait(): If the flush goroutine hangs (e.g., DB write blocks indefinitely),Close()will block forever. Consider adding a timeout viacontext.WithTimeoutor a select with a deadline. Low risk if the flush context is already cancellable.done: Worth confirming that therunFlushLoopselect handles thedonechannel closure by doing one last flush before returning. From the diff this looks correct (the defer handles cleanup).Verdict: Approve. This is a textbook fix for a goroutine lifecycle race.
@clawbot
is the flush context already set up with an appropriate timeout?
Good question. The
flushCtxis just the parentctxfrom the deploy call — it has no dedicated timeout for the final flush.This means if the parent context gets cancelled before or shortly after
Close()is called, the finalAppendLog(flushCtx, data)will fail silently and the last buffered log lines are lost.In practice this is probably fine because
Close()is deferred in the same function that ownsctx, so the context is still alive whenClose()runs. But if you want to be defensive,Close()could usecontext.WithTimeout(context.Background(), 5*time.Second)for the final flush instead of relying on the parent context.As-is, the PR correctly fixes the original bug (not waiting for flush). The context lifetime question is a pre-existing design choice, not introduced by this PR.