undici icon indicating copy to clipboard operation
undici copied to clipboard

Invalid HTTP2 headers should be recoverable

Open dhalbrook opened this issue 5 months ago • 2 comments

Bug Description

If an invalid HTTP2 header is sent by the server, the client should be able to recover by retrying the operation. Right now it results in an uncaughtException. See https://github.com/nodejs/undici/discussions/4341 for more details.

Reproducible By

To reproduce, a mock reply will need to be constructed where an HTTP2 connection to a server gets a response with an HTTP1 header like "http2-settings".

Ideally a runtime error is thrown, which can be caught in a block where Undici can be directed to retry the operation with a new connection.

Logs & Screenshots

Here is an example stack trace from when this occurs:

{err":{"type":"TypeError","message":"HTTP/1 Connection specific headers are forbidden: \"http2-settings\"","stack":"TypeError: HTTP/1 Connection specific headers are forbidden: \"http2-settings\"\n    
at mapToHeaders (node:internal/http2/util:651:13)\n    
at ClientHttp2Session.request (node:internal/http2/core:1813:25)\n    
at writeH2 (/.../node_modules/undici/lib/dispatcher/client-h2.js:469:22)\n    
at Object.write (/.../node_modules/undici/lib/dispatcher/client-h2.js:119:14)\n    
at _resume (/.../node_modules/undici/lib/dispatcher/client.js:601:50)\n    
at resume (/.../node_modules/undici/lib/dispatcher/client.js:303:28\n    
at node:internal/process/task_queues:140:7\n    
at AsyncResource.runInAsyncScope (node:async_hooks:206:9)\n    
at AsyncResource.runMicrotask (node:internal/process/task_queues:137:8)","code":"ERR_HTTP2_INVALID_CONNECTION_HEADERS"}

Environment

This was encountered using Node.js 22 on RHEL9.

Additional context

dhalbrook avatar Jul 22 '25 08:07 dhalbrook

I’d like to try to work on this.

eryue0220 avatar Jul 29 '25 10:07 eryue0220

go for it

metcoder95 avatar Jul 29 '25 10:07 metcoder95