Skip to content

fix(archiver): propagate context in rearchiveRange and fix structured log#59

Open
erhnysr wants to merge 1 commit into
base:masterfrom
erhnysr:fix/rearchive-context-and-logging
Open

fix(archiver): propagate context in rearchiveRange and fix structured log#59
erhnysr wants to merge 1 commit into
base:masterfrom
erhnysr:fix/rearchive-context-and-logging

Conversation

@erhnysr

@erhnysr erhnysr commented May 20, 2026

Copy link
Copy Markdown

Fixes #58.

Changes

1. Context propagation in rearchiveRange

rearchiveRange previously used context.Background() for both retry.Do and persistBlobsForBlockToS3, making it impossible to cancel the operation on archiver shutdown or HTTP request timeout.

  • Changed the function signature to accept context.Context
  • Passed the context through to retry.Do and persistBlobsForBlockToS3
  • Updated the HTTP handler to pass r.Context(), so the 60-second middleware timeout and client disconnects correctly abort the operation
  • Updated the test call site to pass context.Background()

2. Structured logging fix in waitObtainStorageLock

a.log.Crit("failed to write to lockfile: %v", err) passed %v as a key name to the structured logger, silently dropping the error value from log output. Changed to a.log.Crit("failed to write to lockfile", "err", err).

Test plan

  • All existing archiver tests pass (go test ./archiver/...)
  • go build ./... clean
  • Verify rearchive is cancelled when archiver shuts down mid-range
  • Verify lockfile write failure message appears correctly in structured logs

🤖 Generated with Claude Code

… log

Two bugs fixed:

1. rearchiveRange used context.Background() unconditionally, preventing
   cancellation on archiver shutdown or HTTP request timeout. The function
   now accepts a context.Context and passes it to retry.Do and
   persistBlobsForBlockToS3. The HTTP handler passes r.Context() so the
   operation is cancelled when the 60-second middleware timeout fires or
   the client disconnects.

2. waitObtainStorageLock logged the lockfile write failure with a printf-
   style format string ("failed to write to lockfile: %v") instead of a
   structured key/value field, causing the error to be silently swallowed
   by the structured logger. Fixed to use ("failed to write to lockfile",
   "err", err).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@cb-heimdall

Copy link
Copy Markdown
Collaborator

🟡 Heimdall Review Status

Requirement Status More Info
Reviews 🟡 0/1
Denominator calculation
Show calculation
1 if user is bot 0
1 if user is external 0
2 if repo is sensitive 0
From .codeflow.yml 1
Additional review requirements
Show calculation
Max 0
0
From CODEOWNERS 0
Global minimum 0
Max 1
1
1 if commit is unverified 0
Sum 1

@erhnysr

erhnysr commented Jun 21, 2026

Copy link
Copy Markdown
Author

Hi! Just checking in on this PR — happy to address any feedback or rebase if needed. Let me know if there's anything I can clarify about the context propagation fix.

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(archiver): rearchiveRange ignores context — cannot be cancelled on shutdown or HTTP timeout

2 participants