Skip to content

Fix console cursor on BSDs in async context - #100

Closed
havenwood wants to merge 2 commits into
ruby:masterfrom
havenwood:kqueue-console-cursor
Closed

havenwood wants to merge 2 commits into
ruby:masterfrom
havenwood:kqueue-console-cursor

Conversation

@havenwood

Copy link
Copy Markdown

IO.console.cursor errors on kqueue-based systems when used with the fiber scheduler.

require 'async'

Async { IO.console(:cursor) }.wait

This works on Linux but raises Errno::EINVAL: Invalid argument with IO_Event_Selector_KQueue_Waiting_register on macOS.

I don't know if it's an acceptable fix, but this patch just dups file descriptors for stdin/stdout/stderr if detected alongside kqueue.

@havenwood

Copy link
Copy Markdown
Author

I think I'm still leaking and need to properly implement @nobu's advice.

@havenwood

Copy link
Copy Markdown
Author

@ioquatix mentioned an alternative solution would be falling back to blocking I/O with tty devices on kqueue.

@havenwood
havenwood force-pushed the kqueue-console-cursor branch from be65045 to 2f0be27 Compare September 1, 2025 00:26
@havenwood
havenwood force-pushed the kqueue-console-cursor branch 2 times, most recently from 465d378 to cebd424 Compare September 1, 2025 00:32
`IO.console.cursor` errors on kqueue-based systems when used with the
fiber scheduler.

```ruby
require 'async'

Async { IO.console(:cursor) }.wait
```

This works on Linux but raises `Errno::EINVAL: Invalid argument` with
`IO_Event_Selector_KQueue_Waiting_register` on macOS.

I don't know if it's an acceptable fix, but this patch just dups file
descriptors for stdin/stdout/stderr if detected alongside kqueue.
@havenwood
havenwood force-pushed the kqueue-console-cursor branch from cebd424 to 5f0f331 Compare September 1, 2025 05:43
@havenwood

Copy link
Copy Markdown
Author

I meant to follow up that @ioquatix pointed out this is probably better fixed in the io-event gem by making kqueue synchronous for this use case rather than a hacky solution like mine here.

I'd be happy to close this PR and open an Issue if that's preferred. Thanks!

@nobu nobu closed this Oct 26, 2025
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.

2 participants