Skip to content
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

Introduce Fiber::Scheduler#fiber_interrupt. #12585

Closed

Conversation

ioquatix
Copy link
Member

@ioquatix ioquatix commented Jan 16, 2025

Ruby's IO#close can cause IO#read, IO#write, IO#wait, IO#wait_readable and IO#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 and io_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 for IO#close to interrupt a fiber.

This PR introduces a new public C function rb_io_interruptable_operation which takes a callback. During that callback, the code may be interrupted. In addition, we expose that as IO#interruptable_operation{...} which does the same. This allows us to implement IO interruption, e.g.

Fiber.schedule do
  io.interruptible_operation do
    # internal read or wait
  end
end

# Will interrupt above fiber:
io.close

See socketry/io-event#130 for the counterpart PR in the io-event gem, e.g. the user code which adopts this feature.

@ioquatix ioquatix force-pushed the fiber-scheduler-fiber_interrupt branch 4 times, most recently from 0fd3e5c to 09f1395 Compare January 17, 2025 00:08

This comment has been minimized.

@ioquatix ioquatix force-pushed the fiber-scheduler-fiber_interrupt branch 2 times, most recently from 54d287e to 47b9bdb Compare January 17, 2025 03:11
@ioquatix ioquatix force-pushed the fiber-scheduler-fiber_interrupt branch from 47b9bdb to 122dabc Compare March 1, 2025 21:28
@ioquatix ioquatix force-pushed the fiber-scheduler-fiber_interrupt branch 5 times, most recently from 0338268 to faf5619 Compare March 2, 2025 20:48
@ioquatix ioquatix requested review from nobu and ko1 and removed request for nobu March 2, 2025 20:53
@ioquatix ioquatix force-pushed the fiber-scheduler-fiber_interrupt branch 2 times, most recently from 76056a1 to aeff7f3 Compare March 3, 2025 02:38
@ioquatix
Copy link
Member Author

Closing in favour of #12839

@ioquatix ioquatix closed this Mar 10, 2025
@ioquatix ioquatix deleted the fiber-scheduler-fiber_interrupt branch March 10, 2025 09:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants