hyperium / hyper

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

Detecting closed connection race condition #3286

Open bagder opened 1 year ago

bagder commented 1 year ago

Version current git master

Platform Linux (any really)

Description I'm using hyper with curl.

When we do multiple transfers with curl it tries to reuse a connection used in a previous transfer. Persistent connection style. It has a "pool" of previously used connections.

Any such connection in the pool might be closed or otherwise "die" at any given moment.

When curl wants to send a request on a reused connection there is always a risk that it was closed (by the server) just the millisecond before we send the request over the connection.

A key information piece to detect this state is that curl is not able to read a single byte from the connection. If it could read a byte from it, it was not a race condition.

I struggle to get hyper to tell me this information. When hyper deems the response "illegal" very early in the response I get an error back, but how do I know if it errors before reading a single byte?

HYPERE_UNEXPECTED_EOF seems to be returned for more problems than just this.

seanmonstar commented 1 year ago

So, you're trying to distinguish between a sort of "EOF no bytes read" and "EOF some bytes read, but not enough"?