-
Notifications
You must be signed in to change notification settings - Fork 79
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Encoder does not support intermediate flushes before the reader has ended #154
Comments
It sounds like there's 2 parts to this:
For the second part, there's no real way to indicate that from the This would be easy to do in an response.write_all(first_element).await?;
response.flush().await?;
response.write_all(second_element).await?; I'm not sure how to support it for |
right, |
Maybe an option to enable this behavior would be the best approach |
flushing on pending is only one case, we might want to produce data depending on other conditions, like:
So maybe the right way would be to add a |
|
so, thinking a bit more about this, the write oriented API would be a bit cumbersome. For HTTP, I have a Stream of Bytes buffers going in, and must have a Stream of (compressed) Bytes buffers going out. If I use the write oriented approach, I must write into an AsyncWrite that somehow will output them to a Stream of buffers. IIRC that will require having the encoding part in a spawned task and have a channel on the other end. Doable but annoying (are there other solutions for that?). Now, taking a step back: if we want to go from Stream of Bytes to Stream of Bytes, would it be possible to avoid going through AsyncRead and AsyncWrite, and instead pass through the encoder directly, and flush after compressing each chunk? The structures in |
For The |
alright, I'll look into |
it feels like the real complexity here is fitting poll_flush in tower-http's compression layer. It has to interact with |
Now that I am looking around at other crates that use async-compression (and there are a LOT 😀 ), maybe the right approach would be to provide wrappers for encoders and decoders with configurable trapdoors, like flushing when enough data is received, or after enough time without activity. That could keep the |
That could be implemented on top of |
disclaimer: this is about fixing apollographql/router#1572, for which I'm under tight timing constraints, so right now this issue's goal (and the related PR) is discussing and finding a quick fix that we can use directly in the router, and then I'll help find a proper solution.
I'm encountering an issue with the following setup:
CompressionLayer
, which uses async-compressionI tracked that down to async-compression, where in the tokio based
Encoder
, due to the use ofready!()
, whenever the underlying reader returnsPoll::Pending
, it is transmitted directly to the caller, so there is no flush until the entire data has been read:https://github.com/Nemo157/async-compression/blob/ada65c660bcea83dc6a0c3d6149e5fbcd039f739/src/tokio/bufread/generic/encoder.rs#L63-L74
I would like the encoder to send the data it already compressed when the reader returned
Poll::Pending
, and let the upper layer decide on buffering or sending the HTTP chunk directly.The text was updated successfully, but these errors were encountered: