简体   繁体   中英

OCaml Unix Error

I have run into an error that I am not sure how to debug. The error is Exception: (Unix.Unix_error "Too many open files" pipe "") . I am not opening any files and only have a single Unix process open. Anybody have some tips on how to debug this?

The function causing the error is:

 let rec update_act_odrs ?(sec_to_wait = 0.0) () = 
    try         
      (act_odrs := active_orders ())
      |> fun _ -> Lwt_io.print "active_orders Updated\n"
    with _ ->   
      Lwt_unix.sleep sec_to_wait
      >>= update_act_odrs ~sec_to_wait:(sec_to_wait +. 1.0)

where active_orders () is a function that gets JSON data from a server.

I would suggest to use ltrace , to trace the calls to open or pipe function. Also, it is good idea, just to grep your codebase, for functions that usually opens descriptors, eg openfile , socket , pipe , popen .

Also, you should know, that the failing function is not always a root of the evil. The descriptors can be eaten by some other process or function in your process.

You can also look at /proc folder, if you're on linux, to make sure, that your process actually eats so many fd s. Maybe, you have another process in your system, that is launched by your application, and that is responsible for the fd leak.

Finally, from the code you've shown, I can conclude, that the source of leak can be only active_orders function. If it downloads json data from serve, it should open a socket connection. The fact that error message, points to the pipe is strange, maybe it is implemented with popen or system functions.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM