The documentation explains how to set a timeout while waiting for a response from the server, but I don't see how one can set up a timeout while reading the response body without getting a file descriptor leak.
In particular, as far as I can see, with the following code, the file descriptor is not closed as long as the server does not close its side of the connection, which can well never happen if it stops responding.
Lwt.pick
[
(let%lwt _, body =
Cohttp_lwt_unix.Client.get
(Uri.make ~scheme:"http" ~host:"localhost" ~port:8080 ())
in
let%lwt () = Cohttp_lwt.Body.drain_body body in
Lwt.return_unit);
(let%lwt () = Lwt_unix.sleep 6. in
Lwt.return_unit);
]
The documentation explains how to set a timeout while waiting for a response from the server, but I don't see how one can set up a timeout while reading the response body without getting a file descriptor leak.
In particular, as far as I can see, with the following code, the file descriptor is not closed as long as the server does not close its side of the connection, which can well never happen if it stops responding.