ocaml-cohttp
ocaml-cohttp copied to clipboard
Fix `Connection_cache.call` hanging on unreachable server
- 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.
The change looks fine to me but /cc @art-w and @MisterDA who worked on this piece the most recently.
Don’t hesitate to let me know if I can help moving this forward :).