Skip to content

Fix Connection_cache.call hanging on unreachable server #1113

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

lthms
Copy link

@lthms lthms commented Jun 8, 2025

  • 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.

* 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.

* 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.
@samoht
Copy link
Member

samoht commented Jun 17, 2025

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

@lthms
Copy link
Author

lthms commented Jun 29, 2025

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

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

Successfully merging this pull request may close these issues.

Cohttp_lwt_unix.Connection_cache.call hangs if the server is unreachable
2 participants