child-process icon indicating copy to clipboard operation
child-process copied to clipboard

fix: prevent `Process::close()` double execution

Open 7-zete-7 opened this issue 5 months ago • 0 comments

Fixes #116

The Process::close() method contains a block introducing side effects (see https://github.com/reactphp/child-process/blob/1721e2b93d89b745664353b9cfc8f155ba8a6159/src/Process.php#L300-L302). One of the possible side effects may be a repeated call to the Process::close() method. Due to the deferred protection against double execution of the method (below the block with potential side effects, see https://github.com/reactphp/child-process/blob/1721e2b93d89b745664353b9cfc8f155ba8a6159/src/Process.php#L310), the Process::close() method may be run again. The second execution of the Process::close() method will work correctly, but the first will encounter an error about the absence of a resource in the Process::$process property (this property was set to null during the second execution).

With this change, the protection against double execution of the Process::close() method is moved to the very beginning of the method.

7-zete-7 avatar Aug 28 '25 11:08 7-zete-7