fix: return codes.Internal on recovered panic instead of nil error - #46
Open
janwytze wants to merge 1 commit into
Open
fix: return codes.Internal on recovered panic instead of nil error#46janwytze wants to merge 1 commit into
janwytze wants to merge 1 commit into
Conversation
When Repanic is disabled (the default), recoverWithSentry recovered the panic and reported it to Sentry, but the interceptor's unnamed return values fell through to their zero value — a nil error. gRPC then treated the RPC as successful: streaming handlers returned OK with a missing or partial response, and unary handlers returned a nil response that fails to marshal with an opaque "Internal" error, masking the real panic. Give both server interceptors named returns and have recoverWithSentry translate a recovered panic into a status.Errorf(codes.Internal, ...) error (and mark the transaction as failed) on the non-repanic path. Repanic=true behaviour is unchanged. Add tests covering panic recovery, the repanic option, and normal-error pass-through for both unary and stream interceptors.
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.
Problem
When
Repanicis disabled (the default),recoverWithSentryrecovers a handler panic and reports it to Sentry, but the server interceptors use unnamed return values, so after recovery the function falls through to its zero value — anilerror. gRPC then treats the RPC as successful:OKwith a missing/partial response (silent data loss; metrics count it as success).nilresponse that fails to marshal, surfacing as an opaqueInternalerror that masks the real panic.In all cases nothing distinguishes a panicked RPC from a healthy one at the gRPC layer.
Fix
UnaryServerInterceptorandStreamServerInterceptornamed returns.recoverWithSentrytranslate a recovered panic intostatus.Errorf(codes.Internal, "%v", err)(and mark the transactionSpanStatusInternalError) on the non-repanic path.Repanic: truebehaviour is unchanged; normal handler errors pass through unchanged.Tests
Adds tests that actually invoke the interceptors (the existing tests only cover construction):
codes.Internal(unary + stream)WithRepanicOption(true)→ panic propagates (unary + stream)go build,go vet,gofmt, andgo test ./...all pass.