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

H2: shutdown the connection once finished #23

Merged
merged 2 commits into from
Jan 6, 2024

Conversation

reynir
Copy link
Contributor

@reynir reynir commented Jan 5, 2024

The branch https://github.com/reynir/http-lwt-client/tree/test-fd-leak contains a test that reproduces this behavior. It is not included here as it makes some quite brittle assumptions over file descriptor layout.

Closes #22

@@ -268,7 +267,9 @@ let single_h2_request ?config fd scheme user_pass host meth path headers body f
| Some body -> H2.Body.Writer.write_string request_body body
| None -> ());
H2.Body.Writer.close request_body;
finished
finished >|= fun res ->
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're using the Lwt_result.Infix operators in this module -- so I wonder whether the call to shutdown below should be done in all cases (not only the successful ones)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I pushed a commit that handles if finished is somehow cancelled using Lwt.finalize. Otherwise finished returns a result so I think it handles failures already? What do you have in mind?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks fine, the alternative would be:

Lwt.bind finished (fun r -> H2.Client_connection.shutdown connection; Lwt.return r)

I suspect that finalize is preferably - and still suspect that "cancelling http_lwt_client request" may lead to resource leaks... (but that's fine since it was the case before)

@hannesm
Copy link
Contributor

hannesm commented Jan 5, 2024

Nice find. And indeed, in http-mirage-client we call the shutdown.. https://git.robur.coop/robur/opam-mirror/commit/d03cd65dcdbe99d230cac84f2100f74b427a8675

@reynir
Copy link
Contributor Author

reynir commented Jan 5, 2024

Nice find. And indeed, in http-mirage-client we call the shutdown.. https://git.robur.coop/robur/opam-mirror/commit/d03cd65dcdbe99d230cac84f2100f74b427a8675

"Funny" how I arrived at the same solution :)

Copy link
Contributor

@hannesm hannesm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, feel free to merge & cut a release

@reynir reynir merged commit e0ce59b into robur-coop:main Jan 6, 2024
2 checks passed
mseri pushed a commit to ocaml/opam-repository that referenced this pull request Jan 6, 2024
CHANGES:

* Call shutdown in h2 to properly close http2 connections. This fixes a file
  descriptor leak reported in robur-coop/http-lwt-client#22 (robur-coop/http-lwt-client#23, @reynir @hannesm)
@reynir reynir deleted the fix-h2-shutdown branch January 8, 2024 08:59
nberth pushed a commit to nberth/opam-repository that referenced this pull request Jun 18, 2024
CHANGES:

* Call shutdown in h2 to properly close http2 connections. This fixes a file
  descriptor leak reported in robur-coop/http-lwt-client#22 (robur-coop/http-lwt-client#23, @reynir @hannesm)
hannesm added a commit to hannesm/opam-repository that referenced this pull request Aug 28, 2024
CHANGES:

* http2: shutdown the connection once finished (robur-coop/http-lwt-client#23, @reynir)
* update to TLS 1.0 API (robur-coop/http-lwt-client#25, @hannesm)
avsm pushed a commit to avsm/opam-repository that referenced this pull request Sep 5, 2024
CHANGES:

* http2: shutdown the connection once finished (robur-coop/http-lwt-client#23, @reynir)
* update to TLS 1.0 API (robur-coop/http-lwt-client#25, @hannesm)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

File descriptor leak when using h2
2 participants