Closed aatifsyed closed 9 months ago
should be fixed by #255 pending release tomorrow
I think this is still a logic bug - the encoder should not return an error in the given case.
Would you prefer I reword the error issue or open a new one?
Okay. I'd just tested your repro of the panic and saw that it didn't on master.
New issue would be great please.
New issue would be great please.
I'm hitting a
Flush after shutdown
panic, ultimately here: https://github.com/Nullus157/async-compression/blob/ece5584ce59a683c38e94f9957969e1bdb08b665/src/tokio/write/generic/encoder.rs#L97Repro
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.