Repository navigation
runtime: add zio.recancel() - #699
Conversation
Re-arming a cancellation that a cancellation point already reported was only reachable through getCurrentTask().recancel(), i.e. through an internal API. Expose it as zio.recancel(), mirroring std.Io.recancel and the checkCancel/beginShield/endShield wrappers: a no-op outside a task context, where a blocking task's cancellation is never consumed and so needs no re-arming. AnyTask.recancel() asserted user_canceled, which is stricter than std.Io.recancel's "error.Canceled was returned from a prior cancelation point" and does not fit a public API: a task canceled by withTimeout has auto_canceled set instead. Assert the task is under a cancellation of either kind. That also covers waitForIo, which re-arms when an operation completes successfully despite a cancel request and could reach the assert from an auto-cancel.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (5)
Included review availability: Your plan provides up to 4 included reviews per hour; 0 remain after this review. 📝 WalkthroughWalkthroughThe PR adds ChangesCancellation Re-arming
Estimated code review effort: 3 (Moderate) | ~20 minutes Merge Risk: ⚪ Minimal · up to This change exposes cancellation re-arming through the public API and supports both user- and timeout-triggered cancellation paths; no actionable merge-blocking risk remains beyond normal checks and review. Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Re-arming a cancellation that a cancellation point already reported was only reachable through
getCurrentTask().recancel(). This exposes it aszio.recancel(), next tocheckCancel/beginShield/endShield, and it is a no-op outside a task context for the same reasoncheckCancelfalls through to the syscall token there: a blocking task's cancellation is never consumed, so there is nothing to put back.AnyTask.recancel()asserteduser_canceled. That is stricter thanstd.Io.recancel, which asserts only that "error.Canceledwas returned from a prior cancelation point" without caring who requested it (Dispatch/Uringassertcancel_protection.acknowledged,Threadedmarks every non-.canceledstatusunreachable). It also does not fit a public API, since a task canceled bywithTimeouthasauto_canceledset and nouser_canceled. The assert now accepts either kind.That second part is a fix, not just API polish:
waitForIore-arms when an operation completes successfully despite a cancel request, and reaches that path from an auto-cancel whenever awithTimeoutdeadline races an I/O completion, which trips the old assert under runtime safety.One difference from std remains by design: std tracks a boolean
acknowledgedflag and can assert on a double recancel, while zio countspending_errors, which has to tolerate a second real cancel arriving while the first is being handled.Tests: user-cancel re-arm in
runtime.zig, auto-cancel re-arm inautocancel.zig(verifyingwithTimeoutstill attributes the re-delivered error and reportserror.Timeout). The existing net.zig test now uses the public API.