hyperium / hyper

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

Expose a function to check if a `hyper::Error` is due to a `BodyWrite` #3609

Open ClementTsang opened 3 months ago

ClementTsang commented 3 months ago

Is your feature request related to a problem? Please describe.

Originally reported in https://github.com/apache/arrow-rs/issues/5545, where they pointed me to ask some questions here. The gist of the problem is:

When using object_store, we've occasionally hit errors that point to this hyper error:

error writing a body to connection: Broken pipe (os error 32)

We would like to retry this specific error as it seems like something that should be retryable in our use case, but BodyWrite (and Body I suppose) both don't seem to expose any public functions to determine this at a glance.

Describe the solution you'd like

Add a is_body_write() (and maybe a is_body for feature parity with reads) function.

Describe alternatives you've considered

The current workaround we're doing is checking the Display output and checking if it matches the error message associated with BodyWrite - this works but it feels like a terrible workaround and is outright pointed out in the docs to not depend on this behaviour.

Additional context

If there's a better method or a reason this error reason isn't exposed, please let me know!

seanmonstar commented 3 months ago

It's a fair thing to want! The most relevant idea is probably #2845.

Though I also suddenly am reminded of WriteException in Finagle...

ClementTsang commented 2 months ago

👋 So just to be clear, would it make sense to (at least for now) expose is_body/is_body_write until #2845 has more progress made on it? I imagine the latter will take a while, and the former I can submit a PR pretty quickly.