ZstdEncoder
should not panic if tokio::io::AsyncWrite::flush
is called after tokio::io::AsyncWrite::shutdown
#246
Labels
bug
Something isn't working
I'm hitting a
Flush after shutdown
panic, ultimately here:async-compression/src/tokio/write/generic/encoder.rs
Line 97 in ece5584
Repro
Here's an minimal example, which reliably panics on my machine.
Explanation
Here's the sequence of events:
close
flush
es the encoder, whichflush
es the file (writing the zstd header to disk)shutdown
s the encoder, whichshutdown
s the file, but the file returnsPending
.close
again, when the file is ready.flush
es the encoder again, which panicsDiscussion
The bug is basically an interaction between the above code, and this code in
tokio_util
:on docs.rs / on github
A fix could be either:
tokio_util::codec
keeps track of whether it has flushed the inner reader inpoll_close
(not flushing it twice)async_compression
, or enhance its state machine to address the above.I think the right fix is (2):
The documentation for
AsyncWrite
doesn't say that you're not allowed to flush after calling shutdown, in fact, I think implementors should be prepared to handle such a case, at least until shutdown returnsPoll::Ready
.Take the following from the docs:
So following the API, I could write a simple
Transparent<T: AsyncWrite>
wrapper:which, of course, panics if it contains a
ZstdEncoder
.In fact, with the appropriate interleaving of
Poll::Pending
,ZstdEncoder::new(ZstdEncoder::new(...))
will panic.I'm pretty sure this affects all tokio codecs in this crate.
The text was updated successfully, but these errors were encountered: