ocaml-cohttp
ocaml-cohttp copied to clipboard
How to close connections?
I'm not sure if this is related to cohttp, but implementation is a surprise for me as an ordinary developer.
The connection that I get in my handler is not a "real" (fd or channel) - its just a number to distinguish (https://github.com/mirage/ocaml-cohttp/blob/master/cohttp-lwt/src/server.ml#L146),
io_id is not a real connection too - its an abstract Conduit_lwt_unix.flow type. Neither Cohttp.Connection nor Conduit_lwt_unix don't have any close method on these types.
As I understand, I should just exit from my handler with either response or callback and connection would be closed automatically, but it does not happen for keepalive and expert mode. Expert mode is used for example by websocket library (https://github.com/vbmithr/ocaml-websocket) so I can not force-close ws connection on server side - I can only send Close frame to client asking it, but if client is hung I will have many stalled tcp connections and all related lwt threads in my server application.
How have you solved this issue in the meantime?
@mseri We have a "gentlemen's agreement" with client side:) Would be great if this could be fixed some way...
Thanks. I will add it to the things to improve, but I believe this will have to wait for the new conduit/mimic to be able to fix it (ping @dinosaure which may know better)
Yes, this will be fixed. Connection.t is a useless value and will be removed. The individual backends will provide something useful in its stead.