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

Explanation of "connect-in-progress" #721

Open
Wenke-D opened this issue Mar 26, 2024 · 3 comments
Open

Explanation of "connect-in-progress" #721

Wenke-D opened this issue Mar 26, 2024 · 3 comments

Comments

@Wenke-D
Copy link

Wenke-D commented Mar 26, 2024

Hello, when I try to connect a address where there is no tcp server listening, I will get an error (obviously), but the error message is very confusing

Fatal error: exception Eio.Io Net Connection_failure Refused Unix_error (Connection refused, "connect-in-progress", "")

What does the connect-in-progress mean ?

I trace this string down to the eio/lib_eio_posix/low_level.ml

let connect fd addr =
  try
    Fd.use_exn "connect" fd (fun fd -> Unix.connect fd addr)
  with
  | Unix.Unix_error ((EINTR | EAGAIN | EWOULDBLOCK | EINPROGRESS), _, _) ->
    await_writable "connect" fd;
    match Fd.use_exn "connect" fd Unix.getsockopt_error with
    | None -> ()
    | Some code -> raise (Err.wrap code "connect-in-progress" "")

but there is no explanation. Could you please explain a little ?

@talex5
Copy link
Collaborator

talex5 commented Mar 26, 2024

It just means that connect failed.

Connecting is a 3 step process:

  1. Call connect to start connecting (getting EINPROGRESS).
  2. Wait until it's ready.
  3. Call connect again to get the result.

The -in-progress is just a hint that it was the second call that returned the error.

Maybe "connect (collecting result)" or something would be clearer.

@Wenke-D
Copy link
Author

Wenke-D commented Apr 15, 2024

Thanks for the reply, so what does it mean for application ?
In this case, how should I handle this error, if I still want to make the connection ?

@talex5
Copy link
Collaborator

talex5 commented Apr 15, 2024

You can catch connection errors like this:

try ... with Eio.Io (Eio.Net.E Connection_failure _, _) -> ...

(see https://github.com/ocaml-multicore/eio?tab=readme-ov-file#error-handling)

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