From 37102dcc7c7c81e1b7e714626fafe528727f3434 Mon Sep 17 00:00:00 2001 From: Romain Neutron Date: Wed, 11 Sep 2013 21:09:08 +0200 Subject: [PATCH] [Process] Close unix pipes before calling `proc_close` to avoid a deadlock see http://php.net/manual/en/function.proc-close.php --- src/Symfony/Component/Process/Process.php | 5 +++++ .../Component/Process/ProcessPipes.php | 20 ++++++++++++++----- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/Symfony/Component/Process/Process.php b/src/Symfony/Component/Process/Process.php index c0bc715d69..c9224d5e4c 100644 --- a/src/Symfony/Component/Process/Process.php +++ b/src/Symfony/Component/Process/Process.php @@ -310,8 +310,13 @@ class Process } $this->updateStatus(false); + // Unix pipes must be closed before calling proc_close to void deadlock + // see manual http://php.net/manual/en/function.proc-close.php + $this->processPipes->closeUnixPipes(); $exitcode = proc_close($this->process); + // Windows only : when using file handles, some activity may occur after + // calling proc_close while($this->processPipes->hasOpenHandles()) { usleep(100); foreach ($this->processPipes->readAndCloseHandles(true) as $type => $data) { diff --git a/src/Symfony/Component/Process/ProcessPipes.php b/src/Symfony/Component/Process/ProcessPipes.php index 3b29ae9e51..a0fe71c8c1 100644 --- a/src/Symfony/Component/Process/ProcessPipes.php +++ b/src/Symfony/Component/Process/ProcessPipes.php @@ -77,14 +77,24 @@ class ProcessPipes */ public function close() { - foreach ($this->pipes as $offset => $pipe) { - fclose($pipe); - } - + $this->closeUnixPipes(); foreach ($this->fileHandles as $offset => $handle) { fclose($handle); } - $this->fileHandles = $this->pipes = array(); + $this->fileHandles = array(); + } + + /** + * Closes unix pipes. + * + * Nothing happens in case file handles are used. + */ + public function closeUnixPipes() + { + foreach ($this->pipes as $pipe) { + fclose($pipe); + } + $this->pipes = array(); } /**