-
-
Notifications
You must be signed in to change notification settings - Fork 433
Description
Describe the bug
There is a race in proc_open in PHP that is currently not avoided by
setting FD_CLOEXEC on the pipe file descriptors (with the 'e' flag for
the pipes). What happens, in a multithreaded Apache environment, when
multiple rrdtools are attempted to be launched (for example, when a lot
of graphs are requested at once) is this:
Thread 1: creates pipes for stdin/stdout
Thread 2: creates pipes for stdin/stdout
Thread 1: forks process x
Thread 2: forks process y
Process x: inherits pipes from Thread 1 and Thread 2
Process y: inherits pipes from Thread 1 and Thread 2
Process x: closes 'other side' of pipes from Thread 1
Process x: executes rrdtool
Thread 1: closes 'other side' of its pipes
Thread 1: writes command to rrdtool (no trailing newline)
Thread 1: closes stdin pipe to Process x
Process x: receives command from Thread 1
Process x: waits for more data, or stdin to close
Process x: hangs, because the pipe is still open in Process y
Thread 1: waits for data from rrdtool, which never comes
(meanwhile, the same thing happens between Thread 2 and Process y)
This is really a PHP bug, and I'll see if there's a possibility to get
that fixed there, but this at least fixes the problem by allowing
rrdtool to exit, itself, instead of waiting for stdin to be closed.
It seems related to this PHP issue:
https://bugs.php.net/bug.php?id=70932
but the PHP FD_CLOEXEC implementation also has races and does not fix this problem.
To Reproduce
Steps to reproduce the behavior:
Open a graph display page with many graphs. Set the number of columns to 6, maximum graphs to 100.
Wait.
Eventually, with the automatic refresh, there will be hanging processes. strace on them show they are waiting on read on stdin. The graphs related to these do not load, and the refresh will stall.
Expected behavior
Graphs to be plotted correctly, and for rrdtool processes not to hang.
Desktop (please complete the following information)
Gentoo Linux, Apache 2.4.48 with event MPM
PHP 7.4.21
Additional context
Possibly related to this forum thread : https://forums.cacti.net/viewtopic.php?f=2&t=61643
I will be sending a pull request soon with a workaround that seems to be working for me.