0

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.

Thomas
  • 347
  • 3
  • 19
  • Maybe the `active_orders` function do open files? Don't think on lwt anyway, `sleep` and `print` don't open any files. – ivg Jan 25 '15 at 03:05

1 Answers1

1

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, e.g. 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 fds. 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.

ivg
  • 34,431
  • 2
  • 35
  • 63