Skip to content

Commit 5311500

Browse files
author
Nick Harper
committed
Make bin/aphlict behave slightly better when forking
Summary: Due to how file descriptors get inherited when a process forks and the way our script to start/restart stuff works, having bin/aphlict not close STDOUT caused our script to hang. This diff provides a solution; however, something like https://secure.phabricator.com/diffusion/PHU/browse/master/src/daemon/PhutilDaemonOverseer.php;b45eea975f6d9afc$127-129 may be better or more robust. Test Plan: Run our script that calls bin/aphlict in passthru() and see that it no longer hangs. Reviewers: epriestley, vrana Reviewed By: epriestley CC: aran, Korvin Differential Revision: https://secure.phabricator.com/D4240
1 parent 776a240 commit 5311500

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

support/aphlict/server/aphlict_launcher.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,13 @@
8989
} else if ($pid) {
9090
exit(0);
9191
}
92+
// When we fork, the child process will inherit its parent's set of open
93+
// file descriptors. If the parent process of bin/aphlict is waiting for
94+
// bin/aphlict's file descriptors to close, it will be stuck waiting on
95+
// the daemonized process. (This happens if e.g. bin/aphlict is started
96+
// in another script using passthru().)
97+
fclose(STDOUT);
98+
fclose(STDERR);
9299
}
93100

94101

0 commit comments

Comments
 (0)