-
Notifications
You must be signed in to change notification settings - Fork 82
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
(Question) How to sync underlying file correctly? #317
Comments
You can call |
Either I'm missing something or what you're proposing is incorrect. From what I see in public API the only way to finish encoding is to call For files specifically this might not be a problem, because It just seems like the API forces to break shutdown contract "do not read/write after shutdown". |
You could have an intermediate wrapper that doesn't forward shutdown to the underlying file, just flushes it and reports that it has been shutdown. GzipEncoder<NoShutdown<File>> |
Nice, this seems like an actual solution. |
Or you can change it to sync_all on shutdown struct SyncOnShutdownFile {
file: File,
// JoinHandle is fused internally
sync_all: Option<JoinHandle<io::Result<()>>>,
}
impl AsyncWrite {
fn poll_shutdown(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
) -> Poll<io::Result<()>> {
let Self { file, sync_all } = Pin::into_inner(self);
ready!(file.poll_flush(cx));
if sync_all.is_none() {
let file = file.try_clone()?.into_std();
// currently tokio internally spawns, if io-uring is used then it's a different story
*sync_all = tokio::task::spawn_blocking(|| f.sync_all());
}
ready!(Pin::new(sync_all.as_mut().unwrap())).map_err(io::Error::from)??;
file.poll_shutdown(cx)
}
} |
I have a
GzipEncoder<File>
and I need to finalize it.I'd like to call
sync_all()
on it. But before I do that I think I need to finalize encoding first. As far as I understand it is done by calling.shutdown()
on the encoder. But the problem is that it will also call.shutdown()
on the underlying writer's.shutdown()
(link)I believe it's incorrect to call anything that potentially writes to a file after it was shutdown, so I'm in an egg vs chicken kind of situation right here.
Sorry for posting this as an issue, I just don't see any Discussions/forum to ask questions.
The text was updated successfully, but these errors were encountered: