ocaml-git
ocaml-git copied to clipboard
fd leak when reading files from a checkout
Hi,
I'm calling the following function in a loop I'm calling this function in a loop (it's loading a bunch of opam files from a checkout of opam-repository).
let read_opam root pkg =
let open Lwt_result.Syntax in
let* store = Git_unix.Store.v root in
let* commit_id = Git_unix.Store.Ref.resolve store Git.Reference.master in
let open Lwt.Syntax in
let name = OpamPackage.name pkg in
let path =
[
"packages";
Format.asprintf "%a" pp_name name;
Format.asprintf "%a" pp_package pkg;
"opam";
]
in
let* blob_opt = Search.find store commit_id (`Commit (`Path path)) in
match blob_opt with
| None -> assert false
| Some blob -> (
let* r = Git_unix.Store.read store blob in
match r with
| Ok (Blob b) ->
let s = Git.Blob.to_string b in
let opam = OpamFile.OPAM.read_from_string s in
Lwt.return (Ok opam)
| _ -> assert false)
It runs out of fds. According to valgrind --tool=none --track-fds=yes, the files that are not closed are pack files (such as .git/objects/pack/pack-d73621315d08cdcf1ec645c3145974593a0aa945.pack).
I would like these fds to be closed once the data is returned, or as an alternative I think that a "fd pool" approach is possible, so that ocaml-git does not open more than N fds at a time, and closes them all at the end of the pool's lifetime.
Thanks!