-
Notifications
You must be signed in to change notification settings - Fork 285
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
CA-364138 XSI-1217: fix FD leak, Unix.EMFILE #4675
CA-364138 XSI-1217: fix FD leak, Unix.EMFILE #4675
Conversation
lindig
commented
Apr 8, 2022
- Fix file descriptor leak
- Log the number of file descriptors in use when serving a new VM - this is optional but helps to verify the fix
- Currently testing this (after having removed the debugging code that I used to find the leak)
Close both FDs. Signed-off-by: Christian Lindig <christian.lindig@citrix.com>
91b05e1
to
05e22a4
Compare
HTTP error 429 would indicate a rate limit. So: not a code problem so far. |
ocaml/xapi-guard/src/main.ml
Outdated
@@ -22,6 +22,11 @@ let ret v = v >>= Lwt.return_ok |> Rpc_lwt.T.put | |||
|
|||
let sockets = Hashtbl.create 127 | |||
|
|||
let log_fds () = | |||
let fds = Sys.readdir "/proc/self/fd" |> Array.length in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use Lwt_unix.files_of_directory
and then count the number of entries in the Lwt stream if we want to avoid blocking here (Sys.readdir would be a blocking call that blocks all Lwt promises)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let fds = Lwt_unix.files_of_directory "/proc/self/fd" |> Lwt_stream.to_list >|= List.length in
or
let count_stream s = Lwt_stream.fold (fun _ acc -> acc + 1) s 0 in
let fds = Lwt_unix.files_of_directory "/proc/self/fd" |> Lwt_stream.to_list >|= List.length in
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(there are a few more places in varstored_guard that use blocking calls like Sys.file_exists, don't worry about those I'll try to fix those in my PR)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you meant
let stream_length s = Lwt_stream.fold (fun _ acc -> acc + 1) s 0 in
let fds = Lwt_unix.files_of_directory "/proc/self/fd" |> stream_length
The point about blocking is good. On the other hand: the /proc file system is implemented in the kernel and this is called only once we serve a new VM. |
After starting a new server (for a varstored), report the number of open file descriptors in the log. Signed-off-by: Christian Lindig <christian.lindig@citrix.com>
44e79de
to
a4b7d64
Compare
Small addendum: the change to use
|