hyper icon indicating copy to clipboard operation
hyper copied to clipboard

HTTP/2 should send a reset of NO_ERROR instead of CANCEL if already sent response headers

Open maxbear1988 opened this issue 3 years ago • 11 comments

I write a proxy service that use hyper.I upload a file by chrome browser use http2 to my proxy service.In my proxy service,i check the file size by request header content-length and find it is too large, i retrun response with status code 413 without reading the request body immediately.chrome report ERR_HTTP2_PROTOCOL_ERROR, but it is ok in http1.1. I read http2.0 protocol rfc7540 and find program should send RST_STREAM frame with an error code of NO ERROR after sending a complete response. Does hyper provide a solution to this problem?How to solve the problem?

maxbear1988 avatar Dec 30 '21 08:12 maxbear1988

hyper does send a reset frame after you've responded and dropped the request body without reading.

The error seems to suggest it's related to SSL, not to HTTP/2.

seanmonstar avatar Dec 30 '21 15:12 seanmonstar

@seanmonstar thank you. i don't think it is related to SSL. It it performance well in http1.1;if i read the request body,it performance well in http2.0,too. Does hyper send a reset frame with an error code of NO ERROR already?in which version?i don‘t see this code by searching keyword send_reset?I only find send_reset(h2::Reason::INTERNAL_ERROR)

maxbear1988 avatar Jan 04 '22 02:01 maxbear1988

The automatic sending of a reset is handled in h2, a dependency of hyper.

seanmonstar avatar Jan 14 '22 19:01 seanmonstar

@seanmonstar chrome report ERR_HTTP2_PROTOCOL_ERROR ,not ERR_SSL_PROTOCOL_ERROR ,i wrote error last time

maxbear1988 avatar Jan 18 '22 09:01 maxbear1988

Does this happen with other clients? Firefox? curl? Some other language client?

seanmonstar avatar Jan 18 '22 23:01 seanmonstar

@seanmonstar yes,i try chrome,firefox,Microsoft Edge,all report ERR_HTTP2_PROTOCOL_ERROR

maxbear1988 avatar Jan 20 '22 03:01 maxbear1988

@seanmonstar if i read all request body, then response status code 413, it is ok. if i response status code 413 without reading request body, it is not ok.I think hyper should send RST_STREAM frame with error code of NO ERROR after respone status code 413 without waiting for all request body.

maxbear1988 avatar Jan 20 '22 04:01 maxbear1988

@seanmonstar i open hyper trace log,hyper send reset frame with error_code CANCEL. FramedWrite::buffer[0m[1m{[0mframe=Reset { stream_id: StreamId(647), error_code: CANCEL

maxbear1988 avatar Jan 20 '22 12:01 maxbear1988

Ah, I see. So currently, if you drop all handles to the stream while there is still things to read, it will automatically send a reset of CANCEL. The h2 library should be updated to check if (a) we are the server, and (b) if response headers have already been sent, then change to sending a reset of NO_ERROR instead.

seanmonstar avatar Jan 21 '22 21:01 seanmonstar

@seanmonstar do you have a plan to fix this issue?

maxbear1988 avatar Feb 07 '22 02:02 maxbear1988

I have not prioritized fixing this myself, but we welcome contributions if you'd like to join in, or anyone else :)

seanmonstar avatar Feb 08 '22 00:02 seanmonstar

I believe this issue was fixed in https://github.com/hyperium/h2/pull/634

arnauorriols avatar Apr 21 '23 07:04 arnauorriols

Ah yes!

seanmonstar avatar Apr 21 '23 19:04 seanmonstar