Remove context.Background() usage in libs/filer#4657
Conversation
Replace context.Background() with proper context propagation: - Add ctx field to readahead cache, passed at construction time - Update NewReadOnlyWorkspaceFilesExtensionsClient to accept ctx - Simplify NewWorkspaceFilesExtensionsClient and NewReadOnlyWorkspaceFilesExtensionsClient into direct implementations instead of delegating to a shared private function Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Commit: 8950e37
25 interesting tests: 9 FAIL, 7 KNOWN, 7 SKIP, 2 flaky
Top 17 slowest tests (at least 2 minutes):
|
| f Filer | ||
| m sync.Mutex | ||
| f Filer | ||
| ctx context.Context |
There was a problem hiding this comment.
Hrm, this could be surprising and is a known anti-pattern "Do not store Contexts inside a struct type" https://pkg.go.dev/context
Why not update function signatures to pass it everywhere instead?
There was a problem hiding this comment.
The problem is that we have 1) a background process that populates the cache, 2) direct function calls that take a context. The lifetime of 2 is not aligned with the lifetime of 1, so we need different contexts.
It might be possible to not store it though and just pass into the background routine.
Will investigate in a separate PR.
denik
left a comment
There was a problem hiding this comment.
Stamping, since it's better than use of Background, but let's consider removing ctx from the struct in a follow up.
## Summary - Add a gorules lint rule that flags `context.Background()` usage in all files except `main.go`, suggesting `t.Context()` in tests or passing context from the caller - Add context guidelines to AGENTS.md Builds on #4655, #4656, and #4657. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
|
Commit: 911df0f
118 interesting tests: 45 MISS, 42 FAIL, 16 RECOVERED, 8 KNOWN, 4 flaky, 1 PANIC, 1 BUG, 1 SKIP
Top 50 slowest tests (at least 2 minutes):
|
Summary
context.Background()with proper context propagation in the workspace files readahead cachectxfield to cache struct, passed at construction time instead of usingcontext.Background()in worker goroutines and enqueue callsNewReadOnlyWorkspaceFilesExtensionsClientto accept acontext.ContextparameterTest plan
libs/filerandbundle/config/mutator🤖 Generated with Claude Code