Provides low level cross-platform primitives for constructing event loops, with support for select, kqueue, epoll and io_uring.
The initial proof-of-concept Async was built on NIO4r. It was perfectly acceptable and well tested in production, however being built on libev was a little bit limiting. I wanted to directly build my fiber scheduler into the fabric of the event loop, which is what this gem exposes - it is specifically implemented to support building event loops beneath the fiber scheduler interface, providing an efficient C implementation of all the core operations.
Please see the project documentation for more details.
- Getting Started - This guide explains how to use
io-eventfor non-blocking IO.
Please see the project releases for all releases.
- Use
eventfdforURingcross-thread wakeup, and enableIORING_SETUP_SINGLE_ISSUER,IORING_SETUP_DEFER_TASKRUN, andIORING_SETUP_TASKRUN_FLAG. The waking thread now signals viaeventfdrather than submitting aNOPSQE, which unlocks the single-issuer optimisation, defers task work to the application thread, and letsselect()skip theio_uring_get_events()syscall when no task work is pending. - Add support for the
io_closefiber-scheduler hook (Ruby 4.0+). TheURingselector performs the close asynchronously via the ring; theDebug::SelectorandTestSchedulerwrappers forward to the underlying selector when supported. - Improve
WorkerPoolGC compaction support and add proper write barriers, fixing potential use-after-free under compacting GC. - Keep blocked scheduler fibers alive during GC by registering them as roots in
TestScheduler#block, preventing premature collection and the resulting use-after-free crash on resume. - Use Ruby's
xmalloc/xcalloc/xrealloc2/xfreefor all internal selector allocations (the per-fiber ready-queue entries inIO_Event_Selector_ready_push, and both the backing array and per-element allocations inIO_Event_Array). Previously a rawmallocpaired with a debug-build-onlyassert(...)would silently dereferenceNULLand crash in release builds under memory pressure; the Ruby allocators trigger a GC sweep on pressure and raiseNoMemoryError/RangeErroron real failure, so the-1return-code paths throughIO_Event_Array_initialize/_resize/_lookupand their callers inepoll.c/kqueue.c/uring.care removed in favour of straight exception propagation. - Correctly handle short
io_uring_submit()results in theURingselector.io_uring_submit()returns the number of SQEs actually accepted by the kernel and can be short (SQE prep errors,ENOMEM, transientEAGAIN); the old accounting resetpending = 0on any success and silently lost track of unsubmitted SQEs. - Enable
IORING_SETUP_SUBMIT_ALL(kernel 5.18+) on theURingselector so the kernel keeps processing the rest of an SQE batch past individual errors, reducing the frequency of short submits in practice.
- Simplify closed-IO handling in the
Selectselector: rely on Ruby 4'srb_thread_io_close_interruptto wake fibers waiting on a descriptor that's been closed, removing a custom error-recovery path that could mis-attributeIOError/Errno::EBADFto the wrong waiter.
- Add bounds checks, in the unlikely event of a user providing an invalid offset that exceeds the buffer size. This prevents potential memory corruption and ensures safe operation when using buffered IO methods.
- Allow
epoll_pwait2to be disabled via--disable-epoll_pwait2.
- Fix several implementation bugs that could cause deadlocks on blocking writes.
- Fix Windows build.
- Fix
read_nonblockwhen using theURingselector, which was not handling zero-length reads correctly. This allows reading available data without blocking.
- Improved consistency of handling closed IO when invoking
#select.
We welcome contributions to this project.
- Fork it.
- Create your feature branch (
git checkout -b my-new-feature). - Commit your changes (
git commit -am 'Add some feature'). - Push to the branch (
git push origin my-new-feature). - Create new Pull Request.
To run the test suite:
bundle exec bake build
bundle exec susTo make a new release:
bundle exec bake gem:release:patch # or minor or majorIn order to protect users of this project, we require all contributors to comply with the Developer Certificate of Origin. This ensures that all contributions are properly licensed and attributed.
This project is best served by a collaborative and respectful environment. Treat each other professionally, respect differing viewpoints, and engage constructively. Harassment, discrimination, or harmful behavior is not tolerated. Communicate clearly, listen actively, and support one another. If any issues arise, please inform the project maintainers.