tower icon indicating copy to clipboard operation
tower copied to clipboard

Retry middleware improvements for non-cloneable requests

Open fraillt opened this issue 1 year ago • 0 comments

Hello,

I wasn't sure how to contribute to this project, so I hope this is a right place to start discussing.

Basically this revision solves real problem that I had with tonic, using retry middleware. The core of the problem is that tonic (a library that implements gRPC) uses HTTP2, which is by design is streaming protocol. For this reason it is not possible to "clone" tonic request by having just a reference to it. In order to make request clone-able we need to fully consume it, and then reconstruct original object from consumed bytes.

This revision does exactly that.

  1. consumes original request and stores it's content into new user defined CloneableRequest.
  2. later, it recreates back original request from the contents of CloneableRequest.

There's some more discussion related to this:

  • https://github.com/hyperium/tonic/issues/733
  • #682

I think that it doesn't make sense to solve this issue at tonic side, because it's doesn't make sense for tonic to have cloneable request (image situation where client is streaming multi-gibabyte file, how would you consume it? where would you store it? it's not responsibility of tonic). On the other hand, if you want to have retry mechanism, you must be aware that a request will be copied in order to be able to retry it.

Any feedback is welcome :)

fraillt avatar Aug 21 '24 13:08 fraillt