Skip to content

Regression in posix::executor - fd not closed #62

@KiNgMaR

Description

@KiNgMaR

Hi,

8d2bd87 (i.e. upgrading from boost 1.68 to boost 1.69) has introduced a regression where an fd for one of the child process pipes is not closed when there's nothing to read from it.

This leads to fd exhaustion after a while, e.g. with the following piece of code:

    bp::ipstream stdout;
    bp::child diffProcess(bp::search_path("diff"),
        "--unified=1",
        static_cast<std::string>(tmpFile1),
        static_cast<std::string>(tmpFile2),
        bp::std_out > stdout);

    diffProcess.wait();

This patch is a workaround for the single case that we ran into, but there are probably more cases where the fd is not closed either. Please check :)

diff --git a/include/boost/process/detail/posix/executor.hpp b/include/boost/process/detail/posix/executor.hpp
index 1390a58..8b86ed1 100644
--- a/include/boost/process/detail/posix/executor.hpp
+++ b/include/boost/process/detail/posix/executor.hpp
@@ -282,7 +282,10 @@ class executor
                 set_error(std::error_code(err, std::system_category()), "Error read pipe");
         }
         if (count == 0)
+        {
+            ::close(source);
             return  ;
+        }

         std::error_code ec(data[0], std::system_category());
         std::string msg(data[1], ' ');

Thank You & BR,
Ingmar

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions