Skip to content

Commit b184046

Browse files
acoshiftclaude
andauthored
fix: make context cancel unconditional in flush (#15)
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>
1 parent f12dd7c commit b184046

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

quickwit.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,11 +221,11 @@ func (c *Client) loop() {
221221
}
222222

223223
ctx := context.Background()
224+
cancel := context.CancelFunc(func() {})
224225
if t := c.getIngestTimeout(); t != 0 {
225-
var cancel context.CancelFunc
226226
ctx, cancel = context.WithTimeout(ctx, t)
227-
defer cancel()
228227
}
228+
defer cancel()
229229
req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint, bytes.NewReader(buf.Bytes()))
230230
if err != nil {
231231
return false

0 commit comments

Comments
 (0)