fix: prevent NPE in metricsEnd when HTTP/2 stream ends before response headers are received (#6022) [fj4WqyCCw3C5ShR1RfB7MoBPTpkRrBFYP1uT35g3MvT] - #6272
Open
waterWang wants to merge 1 commit into
Conversation
…e headers are received (eclipse-vertx#6022) When using Vert.x HTTP client with HTTP/2, decompression enabled, and micrometer metrics, a NullPointerException occurs in metricsEnd() because handler.response is null. This happens when the stream ends before response headers are processed (e.g., due to decompressor error). The fix adds a null check for stream.response in metricsEnd() before calling metrics.responseEnd(). If the stream ended without receiving response headers, we skip the metrics call since there is no response to report metrics for. Fixes eclipse-vertx#6022
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.
Motivation:
When using Vert.x HTTP client with HTTP/2, decompression enabled, and micrometer metrics enabled, a NullPointerException occurs in Http2ClientConnection.metricsEnd() because handler.response is null.
The stream can reach onEnd before response headers are processed (e.g., when a decompressor error closes the stream). In this case, metricsEnd() calls metrics.responseEnd() which tries to access handler.response.statusCode(), causing NPE.
Modification:
Added a null check for stream.response in metricsEnd() before calling metrics.responseEnd(). If the stream ended without receiving response headers, the metrics call is skipped since there is no response to report metrics for.
This mirrors the existing pattern used elsewhere in the codebase where response availability is checked before metrics access.
Result:
No more NPE when an HTTP/2 stream ends before response headers are received. Metrics are only reported when a response is actually available.
Fixes #6022