ocaml-cohttp icon indicating copy to clipboard operation
ocaml-cohttp copied to clipboard

How to close connections?

Open NightBlues opened this issue 6 years ago • 4 comments

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.

NightBlues avatar Sep 24 '19 15:09 NightBlues

How have you solved this issue in the meantime?

mseri avatar Apr 17 '21 19:04 mseri

@mseri We have a "gentlemen's agreement" with client side:) Would be great if this could be fixed some way...

NightBlues avatar Apr 18 '21 17:04 NightBlues

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)

mseri avatar Apr 18 '21 17:04 mseri

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.

rgrinberg avatar Jan 02 '22 19:01 rgrinberg