Skip to content

Validate selector support at run time.#131

Merged
ioquatix merged 5 commits intomainfrom
io_uring-supported-runtime
Mar 12, 2025
Merged

Validate selector support at run time.#131
ioquatix merged 5 commits intomainfrom
io_uring-supported-runtime

Conversation

@ioquatix
Copy link
Member

@ioquatix ioquatix commented Mar 12, 2025

While io_uring, epoll, and kqueue may be available at compile time, their actual support at runtime is not guaranteed. Various factors, such as kernel configuration, security policies (seccomp, AppArmor, SELinux), or resource limits, may prevent them from working as expected.

This PR introduces explicit runtime checks for each event selector, ensuring that we only define the corresponding constant when the selector is truly available.

While it would be possible to defer these checks until selector creation, this approach follows the existing pattern of defining constants at initialization time, keeping the implementation consistent with the current interface.

Changes

  • Adds IO_Event_Selector_URing_supported_p(), IO_Event_Selector_EPoll_supported_p(), and IO_Event_Selector_KQueue_supported_p(), which attempt to create a minimal instance of each selector to verify availability.
  • Updates Init_IO_Event_Selector_*() to only define the corresponding selector if the runtime check passes.
  • Ensures that systems where a selector is unavailable fail gracefully without requiring conditional compilation.

Why?

  • Prevents runtime failures when attempting to use an unavailable selector.
  • Improves compatibility with sandboxed environments, containers, and restricted runtime configurations.
  • Aligns with existing interface patterns by conditionally defining support constants.

Types of Changes

  • Bug fix.
  • New feature.

Contribution

@ioquatix ioquatix changed the title Io uring supported runtime Validate selector support at run time. Mar 12, 2025
@ioquatix
Copy link
Member Author

Example output:

samuel@aiko ~/D/s/io-event (io_uring-supported-runtime)> sudo sysctl -w kernel.io_uring_disabled=2
kernel.io_uring_disabled = 2
samuel@aiko ~/D/s/io-event (io_uring-supported-runtime)> bundle exec sus
/home/samuel/Developer/socketry/io-event/ext/IO_Event.so: warning: Init_IO_Event_Selector_URing: io_uring_queue_init() was available at compile time but failed at run time: Invalid argument

145 passed 2 skipped out of 147 total (1098 assertions)
🏁 Finished in 162.5ms; 6755.756 assertions per second.
🤩 Your test suite is amazing!
🎉 Great job! Your test suite has excellent performance (6755.8 < 10000)!
🐇 No slow tests found! Well done!
samuel@aiko ~/D/s/io-event (io_uring-supported-runtime)> sudo sysctl -w kernel.io_uring_disabled=0
kernel.io_uring_disabled = 0
samuel@aiko ~/D/s/io-event (io_uring-supported-runtime)> bundle exec sus
194 passed 2 skipped out of 196 total (1230 assertions)
🏁 Finished in 203.9ms; 6032.116 assertions per second.
🤩 Your test suite is amazing!
🎉 Great job! Your test suite has excellent performance (6032.1 < 10000)!
🐇 No slow tests found! Well done!
samuel@aiko ~/D/s/io-event (io_uring-supported-runtime)> 

@ioquatix ioquatix force-pushed the io_uring-supported-runtime branch from b183190 to 3ce0e40 Compare March 12, 2025 22:53
@ioquatix ioquatix merged commit b94bc7b into main Mar 12, 2025
76 of 84 checks passed
@ioquatix ioquatix deleted the io_uring-supported-runtime branch March 12, 2025 23:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant