ocaml-cohttp
ocaml-cohttp copied to clipboard
Ensure cohttp_lwt fd hygiene
From @edwintorok in #315:
I'm still a little worried on what would happen if the connection is reset during reading the headers, or anywhere before the code reaches the place where it either closes the socket or sets up the GC finalizer. Also the close itself seems to be run async, so under high load I'm worried that the close would come too late even in an otherwise well behaved scenario (no errors, close called for each request).
Would it be possible to make this more robust at the API level by providing a with_call/with_callv function that makes the call, applies my [f] function, and does everything needed to ensure that when with_call returns all sockets it used are closed, even if the connection itself, reading the reply headers/body, applying my f, or anything raises an exception?