Skip to content

fix: make context cancel unconditional in flush#15

Merged
acoshift merged 1 commit into
mainfrom
fix/flush-defer-cancel
May 25, 2026
Merged

fix: make context cancel unconditional in flush#15
acoshift merged 1 commit into
mainfrom
fix/flush-defer-cancel

Conversation

@acoshift
Copy link
Copy Markdown
Member

Summary

  • The context cancel function in flush was declared inside a conditional if block and deferred there. While functionally correct, a defer inside a conditional is subtle: if the closure were later refactored to use named returns, the cancellation point would silently shift.
  • Fixed by initializing cancel to a no-op function before the conditional, then deferring it unconditionally. The defer cancel() line is now always present at the top of the HTTP section, making the lifetime of the context cancel unambiguous.

Test plan

  • go test ./... passes (no behavioral change, so no new tests needed)

🤖 Generated with Claude Code

The context cancel function was declared and deferred inside a
conditional block. A defer inside a conditional is correct but subtle —
particularly if the closure were later refactored to use named returns,
the cancel call would silently move. Initialize cancel to a no-op func
upfront so the defer is always unconditional and its scope is obvious at
a glance.

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
@acoshift acoshift merged commit b184046 into main May 25, 2026
1 check passed
@acoshift acoshift deleted the fix/flush-defer-cancel branch May 25, 2026 04:26
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.

1 participant