Repository navigation
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
There was a problem hiding this comment.
Code Review
This pull request adds a 'close' event listener to HTTP/2 requests to reject the request with an ECONNRESET error if the stream closes before the response is fully read, and includes comprehensive unit tests with a local HTTP/2 server. The feedback suggests using a strict equality check req.readableEnded === false instead of !req.readableEnded to avoid potential issues where readableEnded is undefined in mock or custom stream environments.
|
|
||
| req.on('close', () => { | ||
| // A closed stream cannot time out or produce the response the caller is waiting for. | ||
| if (!req.readableEnded) { |
There was a problem hiding this comment.
Using strict equality check req.readableEnded === false is safer and more robust than !req.readableEnded. In some testing environments or when using custom mock streams, the readableEnded property might be undefined. If it is undefined, !req.readableEnded evaluates to true, which would cause successful requests to be incorrectly rejected with ECONNRESET when the stream closes. Checking for explicit false prevents this issue while still correctly identifying prematurely closed streams in all supported Node.js environments.
| if (!req.readableEnded) { | |
| if (req.readableEnded === false) { |
There was a problem hiding this comment.
Updated in 514aded to check req.readableEnded === false explicitly. Native ClientHttp2Stream exposes a boolean, so behavior on supported Node.js versions is unchanged; an undefined property in an incomplete mock no longer triggers this fallback. Re-ran npm test (lint and all 6,470 tests passed), npm run build:tests, and git diff --check.
Discussion
Fixes #3325.
AsyncHttp2Calllistens for response and error events, but a stream can close before response headers without either event. Its request Promise then remains pending, andMessaging.sendEach()cannot finish waiting for all message requests.Reject the request with
ECONNRESETwhenclosefires beforereadableEnded. This uses the existing HTTP client's error translation and configurable retry policy.Checking
readableEndedavoids rejecting a complete response while asynchronous decompression is still finishing. An original stream error that already rejected the Promise is preserved.This does not modify multipart parsing or overlap with the multipart-specific changes proposed in #3324 for #2105. No new timeout, transport switch, dependency, or background process is introduced.
Testing
Added six tests using a real localhost HTTP/2 server:
Before the fix, the first two cases and retry case timed out; the three controls passed. After the fix, all six pass.
The public issue's reproduction was also run against the built SDK: the control succeeds, and both failure cases settle with a failed message result instead of hanging. The verifier allows at least one request rather than exactly one, since a canceled stream now correctly reaches the existing retry policy.
Validation on Windows, Node.js
v26.13.0, npm11.20.0:npm run build— passed.npm run build:tests— passed.npm test— lint passed; 6,470 tests passed.npm run api-extractor— passed; public API reports are unchanged.git diff --check— passed.Emulator-based integration tests were not run locally: the installed Java runtime is 11, whereas the repository's CI uses Java 21. No live-project integration tests were run.
API Changes
None. Public API declarations, dependencies, and retry configuration are unchanged.
Additional context
Prepared with AI assistance. Tests use only localhost, fake credentials, and fake registration tokens; no live FCM requests are made by the reproduction or new regression tests.