-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Allow IO#close
to interrupt IO operations on fibers using fiber_interrupt
hook.
#12839
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: master
Are you sure you want to change the base?
Allow IO#close
to interrupt IO operations on fibers using fiber_interrupt
hook.
#12839
Conversation
This comment has been minimized.
This comment has been minimized.
ee34fe8
to
56d24c9
Compare
For what it's worth this patch makes sense and LGTM, but I have no experience using the fiber scheduler and this needs another reviewer. But thank you for making the changes I suggested 😄 |
IO#close
to interrupt IO operations on fibers using fiber_interrupt
hook.
4836882
to
b69bafb
Compare
cb63a82
to
5694eb1
Compare
5694eb1
to
0c48c46
Compare
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.
Pull Request Overview
This PR introduces a new C function to perform interruptible IO operations in the fiber scheduler, allowing IO#close to interrupt fibers and raise an IOError during blocking operations. Key changes include the implementation of rb_thread_io_blocking_operation with its ensure routine, integration of a new Fiber::Scheduler#fiber_interrupt hook for interrupting fibers, and updated IO buffering and scheduler functions to use the new interruptible operations.
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
Show a summary per file
File | Description |
---|---|
thread.c | Added new functions for interruptible IO operations and modified return type conversion in IO close. |
test/fiber/scheduler.rb | Added exception handling for IO.select and introduced FiberInterrupt and fiber_interrupt functions. |
scheduler.c | Added new scheduler methods that wrap IO methods with the new interruptible blocking operation. |
io_buffer.c | Updated read/write/pwrite functions to correctly resolve IO instances before performing operations. |
internal/thread.h | Declared the new rb_thread_io_blocking_operation function along with updated comments. |
include/ruby/fiber/scheduler.h | Updated documentation for the new fiber_interrupt API. |
NEWS.md | Documented the addition of Fiber::Scheduler#fiber_interrupt for better developer visibility. |
657980d
to
42b1f72
Compare
42b1f72
to
2239ea0
Compare
Ruby's
IO#close
can causeIO#read
,IO#write
,IO#wait
,IO#wait_readable
andIO#wait_writable
to be interrupted with an IOError (stream closed on another thread).The fiber scheduler did not implement this for
io_read
,io_write
andio_wait
hooks. Finally after several years, someone made a bug report - see socketry/async#368 for background. In order to solve this problem for the fiber scheduler, we need to expose the ability forIO#close
to interrupt a fiber.This PR introduces a new internal C function
rb_thread_io_blocking_operation
which takes an IO instance and a callback. During that callback, if the IO is closed, the callback will be interrupted.It also introduces a new fiber scheduler method,
fiber_interrupt
which allows us to interrupt a specific fiber with an error, in this case with anIOError
.https://bugs.ruby-lang.org/issues/21166