hyperium / hyper

An HTTP library for Rust
https://hyper.rs
MIT License
14.42k stars 1.59k forks source link

hyper server send rst after response 503 #3078

Closed maxbear1988 closed 1 year ago

maxbear1988 commented 1 year ago

Version

0.14.20 Platform Linux kwephis1142986 4.18.0-147.5.2.1.h579.eulerosv2r10.x86_64 https://github.com/hyperium/hyper/issues/1 SMP Sat Jul 31 09:58:46 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux Description

I send a POST request with a large body, and the server responds with 503 immediately before reading the body. Then hyper receives the body data at this time and returns the rst message

I expected to see this happen: Hope to close the connection gracefully without sending rst

seanmonstar commented 1 year ago

It's hard to know what happened without see the server code.

But if you replied with a 503 immediately without reading request body, then the OS will usually send a RST since it is closing the connection with data still unread.

maxbear1988 commented 1 year ago

@seanmonstar I found some information about fix this problem. we can use shutdown().If we shutdown the write direction of the connection before calling close, we avoid the RST behavior. can you fix this problem in hyper by calling shutdown before close connection?