fix: return an error instead of panicking when a BufWriter is reused after an error#816
Open
hindriix wants to merge 1 commit into
Open
fix: return an error instead of panicking when a BufWriter is reused after an error#816hindriix wants to merge 1 commit into
hindriix wants to merge 1 commit into
Conversation
…after an error When a future backing `BufWriterState::Prepare` or `Flush` resolved to an error, the `?` operator propagated the error but left the now-completed future in `self.state`. Polling the writer again (via `poll_write`, `poll_flush`, `poll_shutdown` or `put`) re-polled that completed future, panicking with "`async fn` resumed after completion". Transition to a new terminal `BufWriterState::Errored` state when a backing future fails, so subsequent operations surface an error instead of panicking. Closes apache#810
Open
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which issue does this PR close?
Closes #810.
Rationale for this change
BufWriterpanics with`async fn` resumed after completionwhen it isused again after an internal operation has failed.
When the future backing
BufWriterState::Prepare(multipart uploadinitialisation via
put_multipart_opts) orBufWriterState::Flush(
put_opts/upload.finish()) resolves to an error, the?operatorpropagates the error but leaves the now-completed future in
self.state.The next poll (
poll_write,poll_flush,poll_shutdown, or theputconvenience method) re-enters that arm and re-polls the completed future,
which panics inside the generated async state machine:
This is easy to hit in practice: e.g. building a
parquet::arrow::AsyncArrowWriteron top of a
BufWriter, having awritefail, and then callingclose()(or writing again) turns a recoverable error into a panic. As #810 notes,
calling
shutdown/closeafter an error should return an error, not panic.What changes are included in this PR?
BufWriterState::Erroredstate.Prepare/Flushresolves to an error, transitionthe writer into
Errored(dropping the completed future) before returningthe error, so it is never re-polled.
Erroredinput,abort,poll_write,poll_flush, andpoll_shutdownby returning an error rather than panicking.test_buf_writer_reuse_after_error_returns_error)that reproduces the original panic and asserts an error is returned instead,
both for
shutdown-after-error andwrite-after-error.The successful (non-error) code paths are unchanged.
Are there any user-facing changes?
Yes, but only for a previously-panicking path: a
BufWriterwhose internalupload has failed now returns an error from subsequent
write/flush/shutdown/put/abortcalls instead of panicking. There are no public APIor signature changes.