persist: make Pending cancel safe - #38577
Merged
antiguru merged 1 commit intoAug 31, 2026
Merged
Conversation
`Pending::block_until_ready` replaced the state with a `Blocking` placeholder before awaiting the write handle. Dropping the future at that await left the placeholder in place permanently, and every later `into_result` on that `Pending` panicked with "block_until_ready cancelled?". `BatchBuilder` reaches that await in its ordinary write path, in the loop that bounds outstanding part writes, and `finish` reaches `into_result` through the run-completion paths. A caller who drove `BatchBuilder::add` inside a cancellable future and then called `finish`, for example to obtain a `Batch` it could `delete()`, hit an unconditional panic. Since `install_enhanced_handler` aborts the process for any panic outside a catch, that took down the whole process rather than losing the batch. Await the handle through the borrow instead. The state is never taken out, so there is nothing to leave behind and the `Blocking` variant disappears along with its panic. The spawned task keeps running across the cancellation, so a later `block_until_ready` or `into_result` still yields the value. Adds `test_pending_survives_cancellation`, which cancels a `block_until_ready` at its await and then reads the value. Closes: PER-70 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
antiguru
force-pushed
the
per-70-pending-cancel-safe
branch
from
August 31, 2026 07:50
07ef209 to
202899f
Compare
petrosagg
approved these changes
Aug 31, 2026
Member
Author
|
Thanks for the review! |
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.
Pending::block_until_readyreplaced the state with aBlockingplaceholder before awaiting the write handle. Dropping the future at that await left the placeholder in place permanently, and every laterinto_resulton thatPendingpanicked with "block_until_ready cancelled?".BatchBuilderreaches that await in its ordinary write path, in the loop that bounds outstanding part writes, andfinishreachesinto_resultthrough the run-completion paths. A caller who droveBatchBuilder::addinside a cancellable future and then calledfinish, for example to obtain aBatchit coulddelete(), hit an unconditional panic. Sinceinstall_enhanced_handleraborts the process for any panic outside a catch, that lost the whole process rather than the batch. The window is not narrow: for a large batch on object storage the part writes are the bottleneck, so a builder past a few parts spends most of its wall time inside exactly that await.The fix awaits the handle through the borrow instead of taking it out. Nothing is removed from the state, so there is no placeholder to leave behind and the
Blockingvariant disappears along with its panic. The spawned task keeps running across the cancellation, so a laterblock_until_readyorinto_resultstill yields the value.Two items from PER-70 stay open and are not part of this change: a
BatchBuilderteardown that surrenders the parts already written without flushing the buffered one, and removing theore_catch_unwindworkaround that #38482 wraps around its peek-stash blob cleanup, which this fix makes unnecessary.Adds
test_pending_survives_cancellation, which cancels ablock_until_readyat its await point and then reads the value; it fails with the original panic before the fix.Closes: PER-70
🤖 Generated with Claude Code