-
Notifications
You must be signed in to change notification settings - Fork 164
Fix serial runner cancellation #804
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Nice, will take a deeper look early next week 💯 |
| // Wait for the previous task to complete, but cancel it if needed | ||
| if let previousTask, !Task.isCancelled { | ||
| // Always wait for the previous task to maintain serial ordering | ||
| if let previousTask { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm just wondering what would happen if we move this wait before Task (essentially "blocking" run)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NVM, it just breaks the assumptions made in the 3rd test case 👍
70b457f to
4abedc8
Compare
5bf69be to
fd4b1f2
Compare
|
|
pblazej
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I rebased it onto main as my test branch needs more work 👍
Problem
The testSerialRunnerCancel() test was failing with the counter ending up negative (-1, -8, etc.) instead of the expected 0, indicating a race condition.
Root Cause
The condition !Task.isCancelled was causing cancelled tasks to skip waiting for the previous task to complete. This broke the serial execution guarantee, allowing multiple blocks to run concurrently and causing unsynchronized access to the shared counter.
Fix
Removed the !Task.isCancelled condition to ensure all tasks wait for the previous task, even when cancelled. This maintains the serial ordering guarantee that the actor is designed to provide.