Skip to content

persist: make Pending cancel safe - #38577

Merged
antiguru merged 1 commit into
MaterializeInc:mainfrom
antiguru:per-70-pending-cancel-safe
Aug 31, 2026
Merged

persist: make Pending cancel safe#38577
antiguru merged 1 commit into
MaterializeInc:mainfrom
antiguru:per-70-pending-cancel-safe

Conversation

@antiguru

@antiguru antiguru commented Aug 31, 2026

Copy link
Copy Markdown
Member

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 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 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.

Two items from PER-70 stay open and are not part of this change: a BatchBuilder teardown that surrenders the parts already written without flushing the buffered one, and removing the ore_catch_unwind workaround that #38482 wraps around its peek-stash blob cleanup, which this fix makes unnecessary.

Adds test_pending_survives_cancellation, which cancels a block_until_ready at its await point and then reads the value; it fails with the original panic before the fix.

Closes: PER-70

🤖 Generated with Claude Code

@antiguru
antiguru requested a review from a team as a code owner August 31, 2026 07:47
`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
antiguru force-pushed the per-70-pending-cancel-safe branch from 07ef209 to 202899f Compare August 31, 2026 07:50
@antiguru
antiguru requested review from mtabebe and petrosagg August 31, 2026 07:51
@antiguru
antiguru merged commit 951d074 into MaterializeInc:main Aug 31, 2026
84 checks passed
@antiguru

Copy link
Copy Markdown
Member Author

Thanks for the review!

@antiguru
antiguru deleted the per-70-pending-cancel-safe branch August 31, 2026 08:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants