Subject: | DESTROY race condition causes warnings in forked children |
Date: | Wed, 23 Apr 2014 23:08:22 -0500 |
To: | bug-proc-pid-file [...] rt.cpan.org |
From: | Michael Schout <mschout [...] gkg.net> |
When using Proc::PID::File, and then forking off child processes, then
Proc::PID::File's DESTROY() method is called when each child exits. The
problem is that if two children exit very close to each other, then
there is a race condition where DESTROY() calls read(), which in turn
calls flock(), and the flock can issue a warning such as:
(in cleanup) pid "./jnk.pid" already locked: Resource temporarily
unavailable
It appears that you handled this case for threads in DESTROY already by
skipping read() if this is not the main thread.
I worked around it with the attached patch, which essentially does the
same thing if the current PID is not the same as the PID that wrote the
file.
The attached patch eliminates the issue for me.
Message body is not shown because sender requested not to inline it.