ocaml-multicore / eio

Effects-based direct-style IO for multicore OCaml
Other
560 stars 72 forks source link

Getaddrinfo raises error on some backends #351

Open patricoferris opened 2 years ago

patricoferris commented 2 years ago

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.

haesbaert commented 2 years ago

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.

Sudha247 commented 1 year ago

Should we close this, now that Eio doesn't have the luv backend anymore?

talex5 commented 1 year ago

It also affects eio_posix (I've updated the title).

joprice commented 9 months ago

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.