Fix Inconsistent Exit Status in proc_get_status
for PHP Versions Below 8.3
#53820
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR addresses a bug in Symfony's Process component affecting PHP versions prior to 8.3. In these versions, calling
proc_get_status
multiple times on the same process resource only returns the correct exit status on the first call, with subsequent calls returning -1 due to the process being discarded. This behavior can lead to race conditions and incorrect process status reporting in Symfony applications.To resolve this, the PR introduces a workaround that caches the first retrieved exit status. This cached status is then used for subsequent calls, ensuring consistent and accurate exit status reporting. This change aims to align the behavior with PHP 8.3, where this issue has been resolved natively.
Changes:
proc_get_status
calls if PHP version is below 8.3.Proof of Concept:
To demonstrate the issue and the effectiveness of the fix, a proof of concept script is included below. This script uses Symfony's Process component to start a subprocess that outputs a message and exits with a specific status code. The script then attempts to retrieve the exit status of the process using getExitCode(). In PHP versions prior to 8.3, without the proposed fix, this script will often incorrectly report an exit code of -1 due to the race condition described earlier.
Impact:
Testing:
I haven't added tests to this PR because:
I'm really not the type of developer that does not write tests, but I beg my pardon for the reasons above.
Considerations