golang: add nil check in stream complete/destroy callbacks #42965
+8
−0
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.
Commit Message:
golang: add nil guard in stream complete and destroy callbacks
Add nil check in envoyGoFilterOnHttpStreamComplete and
envoyGoFilterOnHttpDestroy to prevent panic when a Go filter
terminates the stream early (e.g., via SendLocalReply).
Without this, subsequent Go filters in the same chain may receive
callbacks on a cleared request context, causing nil pointer dereference.
Additional Description:
If a Go HTTP filter terminates the stream early (e.g., by calling SendLocalReply), Envoy may still call OnStreamComplete and OnDestroy on later Go filters in the chain.
At that point, the request context has already been cleared, so getRequest() returns nil. Without a nil check, the callback panics when trying to use the request.
This change adds a nil guard to both callbacks, so they safely return early if the request is gone.
Risk Level: Low
Testing: N/A
Docs Changes: N/A
Release Notes: Fixed a potential crash in Go HTTP filters when an early-terminating filter causes subsequent Go filters to be invoked on a cleared request context.
Platform Specific Features: N/A
[Optional Runtime guard:]
[Optional Fixes #Issue]
[Optional Fixes commit #PR or SHA]
[Optional Deprecated:]
[Optional API Considerations:]