-
Notifications
You must be signed in to change notification settings - Fork 177
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
Easily reproducible leaking of file descriptors, show stopper. #208
Comments
There is a simplified code snippet to reproduce the issue:
Run The question is why |
I've run into this before as well. I've always done this as a result: Lwt_io.establish_server address (fun (ic, oc) ->
Lwt.async (fun () ->
(* ...close the channels after doing something... *))) I think it's an issue of the generality of the interface. Someone may want to let the channels escape the function, or to A version of |
This could also be addressed with better documentation. I'll add a commit later, but let me know if you have arguments for a new function. |
I suppose there is also the issue of what this hypothetical convenience function should do with exceptions raised by Lwt can't decide for the application how to log or recover, so probably it would have to treat them the way |
Also related: #196. |
I believe these symptoms are due to not trying to close |
I have boiled down my usage to this code sample which will leak file descriptors.
say you have:
and then you create a simple server with:
and then let's start up the OCaml code with
and then open up a client
Then looking at the connections for port 2000 using lsof, we see
ocamlrun 71109 Edgar 6u IPv4 0x7ff3e309cb80aead 0t0 TCP 127.0.0.1:callbook (LISTEN) ocamlrun 71109 Edgar 7u IPv4 0x7ff3e309c9dc8ead 0t0 TCP 127.0.0.1:callbook->127.0.0.1:54872 (CLOSE_WAIT)
In fact for each usage of
nc localhost 2000
, we'll get a leftoverCLOSE_WAIT
record from the lsof usage.Eventually this will lead to the system running out of file descriptors, which will MOST annoyingly not crash the program, but will lead to Lwt to just hang.
I can't tell if I am doing something wrong or if this is a genuine bug, in any case this is a serious bug for me and I run out of file descriptors within 10 hours...
EDIT: It seems to me that the problem is that one side of the connection is closed but the other isn't, I would have thought that
with_connection
should cleanup/close up whenever either side closes.EDIT II: I have tried every which way where I manually close the descriptors with
Lwt_io.close
, but I still have theCLOSE_WAIT
message.EDIT III: Even used Lwt_unix.close on a raw fd given to with_connection's optional fd argument with similar bad results.
EDIT IV: Most insidious is if I use
Lwt_daemon.daemonize
, then this problem seemingly goes awayThe text was updated successfully, but these errors were encountered: