Skip to content

Fix that collect stdout in loop leads to EMFILE #35

@rand00

Description

@rand00

If you run a process via collect stdout in a tight loop, you get the EMFILE exception:

let () =
  while true do
    let date = process "date" [] |> collect stdout in
    print_endline date
  done

.. but if you do the same with run, there is no problem:

let () =
  while true do
    process "date" [] |> run
  done

The exception:

Exception: Unix.Unix_error(Unix.EMFILE, "dup", "")
Raised by primitive operation at unknown location
Called from Feather.exec in file "src/feather.ml", line 201, characters 4-122
Called from Feather.collect in file "src/feather.ml", line 413, characters 22-44
Called from unknown location
Called from Stdlib__Fun.protect in file "fun.ml", line 33, characters 8-15
Re-raised at Stdlib__Fun.protect in file "fun.ml", line 38, characters 6-52
Called from Topeval.load_lambda in file "toplevel/byte/topeval.ml", line 89, characters 4-150
utop: pipe: Too many open files
Raised by primitive operation at unknown location
Called from Feather.exec in file "src/feather.ml", line 201, characters 4-122
Called from Feather.collect in file "src/feather.ml", line 413, characters 22-44
Called from Feather.terminate_child_processes in file "src/feather.ml", line 623, characters 2-71
Called from Stdlib.at_exit.new_exit in file "stdlib.ml", line 561, characters 4-15
Called from Stdlib.exit in file "stdlib.ml", line 569, characters 2-15
Called from Stdlib__Arg.parse_and_expand_argv_dynamic_aux in file "arg.ml", line 279, characters 11-20
Called from Stdlib__Arg.parse in file "arg.ml", line 300, characters 4-31
Called from UTop_main.main_aux in file "src/lib/uTop_main.ml", line 1482, characters 2-36
Called from UTop_main.main_internal in file "src/lib/uTop_main.ml", line 1526, characters 4-25

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions