-
Notifications
You must be signed in to change notification settings - Fork 40
fix(worker): deliver fiber activity cancellation via scheduler fiber_… #519
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -39,8 +39,21 @@ def set_activity_context(defn, context) | |||||||||||||||||
| return unless defn.cancel_raise | ||||||||||||||||||
|
|
||||||||||||||||||
| fiber = ::Fiber.current | ||||||||||||||||||
| # Cancel callbacks run on the canceler's fiber, which for activity cancellation is the | ||||||||||||||||||
| # worker's single task-dispatch fiber. Fiber#raise uses resume semantics, so under a | ||||||||||||||||||
| # scheduler that drives fibers with Fiber#transfer (e.g. async) the target never returns | ||||||||||||||||||
| # to its resumer and the dispatch fiber is suspended forever, wedging the whole worker. | ||||||||||||||||||
| # Schedulers expose fiber_interrupt (Ruby 3.3+) to perform the raise themselves, which | ||||||||||||||||||
| # returns to the caller immediately. | ||||||||||||||||||
|
Comment on lines
+42
to
+47
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unsure if all of the words in the comment are useful.
Suggested change
|
||||||||||||||||||
| scheduler = ::Fiber.scheduler | ||||||||||||||||||
| scheduler = nil unless scheduler.respond_to?(:fiber_interrupt) | ||||||||||||||||||
| context&.cancellation&.add_cancel_callback do | ||||||||||||||||||
| fiber.raise(Error::CanceledError.new('Activity canceled')) | ||||||||||||||||||
| error = Error::CanceledError.new('Activity canceled') | ||||||||||||||||||
| if scheduler | ||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't want to use
Suggested change
|
||||||||||||||||||
| scheduler.fiber_interrupt(fiber, error) | ||||||||||||||||||
| else | ||||||||||||||||||
| fiber.raise(error) | ||||||||||||||||||
| end | ||||||||||||||||||
| end | ||||||||||||||||||
| end | ||||||||||||||||||
| end | ||||||||||||||||||
|
|
||||||||||||||||||
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.
From what I see, this just got added in Ruby 4