eio icon indicating copy to clipboard operation
eio copied to clipboard

Getaddrinfo raises error on some backends

Open patricoferris opened this issue 3 years ago • 4 comments

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.

patricoferris avatar Oct 19 '22 19:10 patricoferris

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.

haesbaert avatar Oct 19 '22 21:10 haesbaert

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

Sudha247 avatar Sep 27 '23 08:09 Sudha247

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

talex5 avatar Sep 27 '23 09:09 talex5

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.

joprice avatar Jan 24 '24 13:01 joprice