Skip to content

Fix context cancellation leaks in consumer polling worker#2

Open
yshengliao wants to merge 2 commits into
mainfrom
claude/fix-go-vulnerabilities-IKthn
Open

Fix context cancellation leaks in consumer polling worker#2
yshengliao wants to merge 2 commits into
mainfrom
claude/fix-go-vulnerabilities-IKthn

Conversation

@yshengliao

Copy link
Copy Markdown
Member

Summary

This PR fixes context cancellation leaks by properly calling cancel() on contexts created with context.WithTimeout(). Additionally, it updates Go version requirements and dependencies to more recent versions.

Key Changes

  • consumerPollingWorker.go: Fixed context leak by capturing and deferring the cancel function from context.WithTimeout() before waiting on ctx.Done()
  • consumer_test.go: Fixed context leak in test by capturing the cancel function and deferring its call
  • go.mod: Updated Go version from 1.21 to 1.25.0 and updated dependencies:
    • github.com/jackc/pgx/v5 from v5.7.1 to v5.9.0
    • OpenTelemetry packages to v1.43.0
    • Various indirect dependencies to their latest versions

Implementation 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

claude added 2 commits May 12, 2026 05:57
- 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
Copilot AI review requested due to automatic review settings May 12, 2026 09:15

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 cancel function.
  • Update go.mod to a newer Go version and bump key dependencies (pgx v5, OpenTelemetry, and others).
  • Refresh go.sum accordingly.

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.

Comment thread go.mod
go 1.21

toolchain go1.22.3
go 1.25.0
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.

3 participants