eio
eio copied to clipboard
Getaddrinfo raises error on some backends
It seems that luv raises an exception instead of returning an empty list.
open Eio
let lookup net hostname =
match Net.getaddrinfo_stream net hostname with
| [] -> ()
| _ -> assert false
let () =
let hostname = "blahblahblah.tarides.com" in
(assert (Unix.getaddrinfo hostname "" [] = []));
Eio_main.run (fun env -> lookup env#net hostname)
This returns:
Fatal error: exception Eio_luv.Luv_error(EAI_NONAME) (* unknown node or service *)
I can't currently run this properly on Linux with Uring but I'm assuming it returns [] because Unix.getaddrinfo does.
Aye, it returns empty as you expected.
The thing is Unix.getaddrinfo completely ignores errno, it simply checks if it got 0 and then tries to build a list, returning empty if nothing is there.
We should probably do the same, catch all Luv_errors and return an empty list.
Should we close this, now that Eio doesn't have the luv backend anymore?
It also affects eio_posix (I've updated the title).
I'm hitting an issue via cohttp-eio with a statically compiled binary using musl, where getaddrinfo fails to resolve dns names. I hit this branch https://github.com/mirage/ocaml-cohttp/blob/3cd08e5a34d38a322055390b86f4b5dd6bdc01e7/cohttp-eio/src/client.ml#L82 with the error "failed to resolve hostname". It seems not relying on the glibc getaddrinfo would be nice for this reason as well.