Skip to content

fix: replace context.TODO() with context.Background() in 6 fire-and-forget call sites#99

Open
KorsarOfficial wants to merge 2 commits intoyandex:mainfrom
KorsarOfficial:fix/context-background
Open

fix: replace context.TODO() with context.Background() in 6 fire-and-forget call sites#99
KorsarOfficial wants to merge 2 commits intoyandex:mainfrom
KorsarOfficial:fix/context-background

Conversation

@KorsarOfficial
Copy link
Copy Markdown

@KorsarOfficial KorsarOfficial commented Mar 18, 2026

Closes #95

Semantic analysis

context.TODO() and context.Background() are both non-nil, non-cancellable root contexts, but carry different intent signals:

context.TODO() context.Background()
Documented meaning Placeholder — decision deferred Correct root context for background/startup
Static analysis tools Flag as "unresolved" Clean
Code review signal "we don't know yet" "intentional root context"

Only sites where Background() is the final correct choice are changed. Sites with // TODO: this context should be tied to e.g. Run() duration are intentionally left as context.TODO() — the placeholder semantics are correct there.

Files changed (6)

File Location
agent/collector/pkg/dso/map.go ccache onDelete callback (no parent context available)
agent/collector/pkg/dso/parser/parser.go constructor log statement
internal/binaryprocessor/binaryprocessor.go constructor initialization
pkg/kafka/producer/producer.go Kafka producer constructor
pkg/profile_event/signal_profile_processor/service.go service constructor
pkg/s3/http_proxy.go proxy after updater shutdown

Δ logic = 0. Mechanical substitution only at sites where the intent is unambiguous.

@KorsarOfficial KorsarOfficial force-pushed the fix/context-background branch from bbeaf75 to 3c19e05 Compare March 18, 2026 20:56
@KorsarOfficial KorsarOfficial changed the title fix: replace context.TODO() with context.Background() in 11 long-lived goroutines fix: replace context.TODO() with context.Background() in 6 fire-and-forget call sites Mar 18, 2026
@KorsarOfficial
Copy link
Copy Markdown
Author

📄 Full analysis report (PDF): 08-perforator-optimizations.pdf

Covers complexity analysis, concurrency audit, and verification for all 7 optimizations.

@MikailBag
Copy link
Copy Markdown
Contributor

I can't agree that using empty context is right in any of these cases.

For logging it looses key-value pairs, for cancellation is causes goroutine leaks (incl. in tests).

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.

fix: replace context.TODO() with context.Background() in background/startup paths

2 participants