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
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/http_lwt_client.ml
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,7 @@ let single_h2_request ?config fd scheme user_pass host meth path headers body f
Lwt.wakeup_later notify_finished v;
w := true
in
let on_eof response data () = wakeup (Ok (response, data))
in
let on_eof response data () = wakeup (Ok (response, data)) in
let response_handler response response_body =
let response : response = {
version = { major = 2 ; minor = 0 } ;
Expand Down Expand Up @@ -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)

H2.Client_connection.shutdown connection;
res

let alpn_protocol = function
| `Plain _ -> None
Expand Down
Loading