ocaml-cohttp icon indicating copy to clipboard operation
ocaml-cohttp copied to clipboard

Fix `Connection_cache.call` hanging on unreachable server

Open lthms opened this issue 5 months ago • 1 comments

  • What

The Connection_cache.call function could hang indefinitely when attempting to establish a connection to an unreachable server. This change resolves that issue by ensuring that the connection creation process is asynchronous and non-blocking.

Fixes #1112

  • Why

Previously, the Connection.create function returns before the connection is established. When the returned connection is binded, something in the code of get_connection prevents the correct handling of the ECONNREFUSED Unix error.

  • How

The create helper function now uses Connection.connect (which returns an Lwt promise) and binds its result using >>=. This transforms the create function itself into an Lwt promise. Consequently, the Connection_cache.call function no longer blocks on connection establishment but rather awaits the connection promise.

lthms avatar Jun 08 '25 20:06 lthms

The change looks fine to me but /cc @art-w and @MisterDA who worked on this piece the most recently.

samoht avatar Jun 17 '25 15:06 samoht

Don’t hesitate to let me know if I can help moving this forward :).

lthms avatar Jun 29 '25 09:06 lthms