-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Open
Labels
bugObserved behavior contradicts documented or intended behaviorObserved behavior contradicts documented or intended behaviorenhancementSolving this issue will likely involve adding new logic or components to the codebase.Solving this issue will likely involve adding new logic or components to the codebase.standard libraryThis issue involves writing Zig code for the standard library.This issue involves writing Zig code for the standard library.
Milestone
Description
Extracted from #25592.
Example:
while (true) {
try t.checkCancel();
// <---------------- what if the signal arrives here?
switch (posix.errno(posix.system.mkdirat(dir.handle, sub_path_posix, mode))) {
.SUCCESS => return,
.INTR => continue,If the signal arrives between checkCancel and the syscall, it will be missed, causing the syscall to be uninterruptible.
To fix this, make the atomic canceling thread id also have some more enum states:
- will check for cancellation later
- cancel request (by thread id)
- uninterruptible
- about to enter interruptible syscall
Then, requestCancel will do a compare exchange to request cancellation, handling previous value:
- will check for cancellation later -> cancellation has been acknowledged
- cancel request -> redundant cancellation request, nothing to do
- uninterruptible -> cannot cancel, nothing to do
- about to enter interruptible syscall -> send the IO signal to interrupt the syscall, then repeat the cancellation request (after a delay?)
Simultaneously, checkCancel will transition the state.
This ensures that signals are only sent when there is a blocking syscall involved, and the repeated attempts handle the signal being delivered during the race window.
Metadata
Metadata
Assignees
Labels
bugObserved behavior contradicts documented or intended behaviorObserved behavior contradicts documented or intended behaviorenhancementSolving this issue will likely involve adding new logic or components to the codebase.Solving this issue will likely involve adding new logic or components to the codebase.standard libraryThis issue involves writing Zig code for the standard library.This issue involves writing Zig code for the standard library.