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

Crash on writing to /dev/null on macOS #757

Open
aaronjeline opened this issue Oct 1, 2024 · 5 comments
Open

Crash on writing to /dev/null on macOS #757

aaronjeline opened this issue Oct 1, 2024 · 5 comments

Comments

@aaronjeline
Copy link

Attempting to use Eio.Flow.copy_string when stdout points to /dev/null crashes.
main.ml:

open Eio

let main env =
    let stdout = Stdenv.stdout env in
    Eio.Flow.copy_string "Hello world!" stdout;
    ()

let () = Eio_main.run main

dune:

(executable
 (public_name demo)
 (name main)
 (libraries eio_main demo))

Interacting with it:

% dune exec demo
Hello world!
% dune exec demo > out
% cat out -p
Hello world!
% dune exec demo > /dev/null
Fatal error: exception File "lib_eio_posix/sched.ml", line 155, characters 2-8: Assertion failed

Eio version: 1.1
@aaronjeline
Copy link
Author

Looks like this is an issue with MacOS poll(), doesn't seem like it supports block devices. (https://nathancraddock.com/blog/macos-dev-tty-polling/).
I'm happy to work on supporting this, I see two ways of going about it, not sure which you think is best?

  1. Special case the handling of block devices, and use select for them.
  2. Spawn a new thread for monitoring blocks devices, use select in that thread, and pipe data from that to the main thread, monitor that second thread as normal with poll

If you have better ideas I'm also happy to hear that.

@talex5
Copy link
Collaborator

talex5 commented Oct 1, 2024

Oh wow, that's annoying. I guess we need to do what libuv does then and use select when polling fails (https://github.com/libuv/libuv/blob/731adacad2426d349d4c51ca608184f7e01c93c6/src/unix/stream.c#L287).

https://lists.apple.com/archives/Darwin-dev/2006/Apr/msg00066.html

There's an issue with binary compatibility inside the kernel that prevented it being fixed in Tiger, but hopefully it can be sorted in Leopard because it's an ongoing headache.

@aaronjeline
Copy link
Author

aaronjeline commented Oct 1, 2024

sorted in Leopard

lol.
Like I said, happy to hack on this if you'd like me to

@aaronjeline
Copy link
Author

Blog post on the trick uv does, I'll start down this road: https://code.saghul.net/2016/05/libuv-internals-the-osx-select2-trick/

@talex5
Copy link
Collaborator

talex5 commented Oct 2, 2024

Sounds good!

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

No branches or pull requests

2 participants