Skip to content

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
eclipse-vertx:4.xfrom
waterWang:fix-npe-metricsEnd-6022
Open

fix: prevent NPE in metricsEnd when HTTP/2 stream ends before response headers are received (#6022) [fj4WqyCCw3C5ShR1RfB7MoBPTpkRrBFYP1uT35g3MvT]#6272
waterWang wants to merge 1 commit into
eclipse-vertx:4.xfrom
waterWang:fix-npe-metricsEnd-6022

Conversation

@waterWang

Copy link
Copy Markdown

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

…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
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.

1 participant