HTTP2 Requests hang upon receiving 'Stream closed with error code NGHTTP2_INTERNAL_ERROR'
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 7.7k
- Forks
- 880
- Avg merge
- 2d 16h
- Merged PRs (30d)
- 68
Description
Bug Description
If node closes a http2stream with NGHTTP2_INTERNAL_ERROR, the await dispatch in httpNetworkFetch() in fetch/index.js will never resolve
Reproducible By
The tricky part about reproducing is understandably getting node to throw this error. Reproductions seem related to sending many large http2 post requests via the fetch api to the same endpoint while the event loop is busy.
Expected Behavior
The promise is rejected rather than left unfulfilled.
Logs & Screenshots
With NODE_DEBUG=http2 I can see code 2 (NGHTTP2_INTERNAL_ERROR) being thrown
[2024-01-30T22:18:35.084Z] [phase_0 saas_local_webhook] [err] HTTP2 14: Http2Stream 3 [Http2Session client]: closed with code 0, closed false, readable false
[2024-01-30T22:18:35.084Z] [phase_0 saas_local_webhook] [err] HTTP2 14: Http2Stream 3 [Http2Session client]: destroying stream
[2024-01-30T22:18:40.109Z] [phase_0 saas_local_webhook] [err] HTTP2 14: Http2Stream 3 [Http2Session client]: shutting down writable on _final
[2024-01-30T22:18:42.118Z] [phase_0 saas_local_webhook] [err] HTTP2 14: Http2Stream 3 [Http2Session client]: closed with code 2, closed false, readable true
[2024-01-30T22:18:42.118Z] [phase_0 saas_local_webhook] [err] HTTP2 14: Http2Stream 3 [Http2Session client]: destroying stream
If i add a call to errorRequest here in writeH2() i can see the following error and my expected behavior of rejecting the promise
[2024-01-30T22:18:42.122Z] [phase_0 saas_local_webhook] [err] [1/30/2024, 5:18:41 PM] [PLATFORM_FETCH] Error resulted from fetch for request POST
{
"stack": "TypeError: fetch failed\n at Object.fetch9 (/nix/store/qwj14ylfz8y3ji41rgzssgk25i4wp749-esbuild_node/depengine_worker.js:31730:19)\n at processTicksAndRejections (node:internal/process/task_queues:96:5)",
"message": "fetch failed",
"cause": {
"stack": "Error [ERR_HTTP2_STREAM_ERROR]: Stream closed with error code NGHTTP2_INTERNAL_ERROR\n at new NodeError (node:internal/errors:372:5)\n at ClientHttp2Stream._destroy (node:internal/http2/core:2339:13)\n at _destroy (node:internal/streams/destroy:109:25)\n at ClientHttp2Stream.destroy (node:internal/streams/destroy:71:5)\n at Http2Stream.onStreamClose (node:internal/http2/core:549:12)",
"message": "Stream closed with error code NGHTTP2_INTERNAL_ERROR"
}
}
Primary question
Why is errorRequest used only in the frameError handler and not the error handler? How else should this promise end up rejected?
Environment
Undici: 5.28.1
OS: nixos 5.23.11
Node: v18.18.2
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in fetch/index.js at httpNetworkFetch() and then inspect the writeH2() error handling in lib/client.js, including the frameError and error handlers. Reproduce the HTTP/2 stream failure with the described large POST workload and verify that an NGHTTP2_INTERNAL_ERROR causes the fetch promise to reject rather than remain pending.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, nodejs
- Domain
- networking
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100