Fix context cancellation leaks in consumer polling worker#2
Open
yshengliao wants to merge 2 commits into
Open
Conversation
- github.com/jackc/pgx/v5 v5.7.1 -> v5.9.0 (CVE-2026-33816, CVE-2026-41889) - go.opentelemetry.io/otel/sdk v1.16.0 -> v1.43.0 (CVE-2026-39883) - golang.org/x/crypto removed by go mod tidy (CVE-2024-45337, CVE-2025-22869, CVE-2025-58181, CVE-2025-47914) - bump go directive to 1.25.0 as required by pgx v5.9.0 https://claude.ai/code/session_011w4atyCxeMXgBSt6gfAiJS
go vet flagged two sites where the cancel function from context.WithTimeout was discarded, leaking the timer until expiry. Capture and call cancel in both the polling worker pause loop and the consumer test. https://claude.ai/code/session_011w4atyCxeMXgBSt6gfAiJS
There was a problem hiding this comment.
Pull request overview
This PR addresses potential context/timer resource leaks by ensuring cancel() is called for context.WithTimeout() usages, and updates the module’s Go version and dependency set to newer releases.
Changes:
- Ensure timeout contexts in the consumer polling worker and test capture and call the returned
cancelfunction. - Update
go.modto a newer Go version and bump key dependencies (pgx v5, OpenTelemetry, and others). - Refresh
go.sumaccordingly.
Reviewed changes
Copilot reviewed 3 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
consumerPollingWorker.go |
Captures cancel from context.WithTimeout and invokes it after the pause timeout completes. |
consumer_test.go |
Defers cancel() for the test timeout context to ensure cleanup on all exits. |
go.mod |
Updates Go version requirement and upgrades dependencies. |
go.sum |
Updates checksums to match the new module graph. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| go 1.21 | ||
|
|
||
| toolchain go1.22.3 | ||
| go 1.25.0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR fixes context cancellation leaks by properly calling
cancel()on contexts created withcontext.WithTimeout(). Additionally, it updates Go version requirements and dependencies to more recent versions.Key Changes
context.WithTimeout()before waiting onctx.Done()github.com/jackc/pgx/v5from v5.7.1 to v5.9.0Implementation Details
The context cancellation fixes ensure that resources associated with the timeout contexts are properly released. Previously, the cancel functions were being discarded (using
_), which could lead to resource leaks. Now they are properly captured and called to clean up the context's internal state.https://claude.ai/code/session_011w4atyCxeMXgBSt6gfAiJS