Guard nil Sentry hub in fail() and fix EOF recovery order#36
Open
ffittschen wants to merge 1 commit into
Open
Conversation
fail() is the shared error helper for every azureblob path (GET download, HEAD, and the PUT/block/multipart save path), so both defects below reach all of them, not only the download that first surfaced them. Together they turn a transient mid-stream S3 read interruption — or any serve error when Sentry is not configured — into a hard, unrecoverable "socket hang up" on the client: - fail() dereferenced the Sentry hub from the request context unconditionally. sentry.GetHubFromContext returns nil when Sentry is not initialized, so any serve error panicked the handler goroutine; net/http then closed the connection mid-response. Guard the hub so reporting is skipped when none is configured. - The io.ErrUnexpectedEOF Range-retry recovery in proxyCacheEntryDownload ran *after* fail(), so it was never reached (fail panicked first). Reorder so a recoverable early close is retried, and only fail when recovery is inapplicable or fails. Add a regression test asserting fail() does not panic and still writes the error response when no Sentry hub is attached to the request.
ffittschen
marked this pull request as ready for review
July 7, 2026 12:47
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.
This PR fixes a nil-pointer panic on the
azureblobpath and a dead recovery branch that together turn a transient error — or any serve error when Sentry is not configured — into a client-visible "socket hang up".The root cause is
fail(), the shared error helper for everyazureblobpath (the GET download proxy, HEAD, and the PUT/block/multipart save path). It dereferences the Sentry hub unconditionally:sentry.GetHubFromContextreturnsnilwhen Sentry is not initialized, so any serve error panics the handler goroutine andnet/httpcloses the connection mid-response. This PR guards the hub so reporting is skipped when none is configured, which fixes the panic across all of those paths at once.A second defect compounds it: in
proxyCacheEntryDownloadtheio.ErrUnexpectedEOFRange-retry recovery runs afterfail(), so it is dead code (fail()panics first). This PR reorders recovery beforefail()so a recoverable mid-stream close is retried instead of turned into a hard failure.Fixes #34.
How to test
go build ./...andgo vet ./internal/protocols/azureblob/are clean.go test ./internal/protocols/azureblob/...passes, including the newTestFailWithoutSentryHubDoesNotPanic— it panics against the pre-fixfail()and passes on the fix.go test ./...suite requires Docker/LocalStack (testcontainers) and was not run in my environment; the offlineazureblobunit tests pass.