Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Fix Inconsistent Exit Status inproc_get_status for PHP Versions Below 8.3#53820

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
Luc45 wants to merge8 commits intosymfony:7.1fromLuc45:patch-1

Conversation

@Luc45
Copy link
Contributor

@Luc45Luc45 commentedFeb 7, 2024
edited
Loading

QA
Branch?5.4, 6.4, 7.0
Bug fix?yes
New feature?no
Deprecations?no
IssuesN/A
LicenseMIT

This PR addresses a bug in Symfony's Process component affecting PHP versions prior to 8.3. In these versions, callingproc_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:

  • Added caching mechanism for the exit status in the Process component.
  • Ensured the cached status is used for subsequentproc_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.

<?phpif (getenv('OUTPUT' ) ) {#echo 'This should fail when "wait" gets large';sleep(2 );echo'This should fail even when "wait" is small';die(123 );}useSymfony\Component\Process\Process;require_once__DIR__ .'/vendor/autoload.php';do {// Increasingly bigger waits.static$wait =0;$wait +=100000;echosprintf('Wait: %s',$wait ) .PHP_EOL;$p =newProcess( ['php',__FILE__ ],__DIR__, ['OUTPUT' =>1,] );$p->start(function (string$type,string$out )use ($p ) {echo$out .PHP_EOL;/** * Calling most methods in Symfony Process that triggers * updateStatus() can potentially trigger the -1 bug. * * @see Process::updateStatus() */echosprintf('Is Running: %s',$p->isRunning() ?'Yes' :'No' ) .PHP_EOL;echosprintf('Exit Code: %s',$p->getExitCode() ) .PHP_EOL;} );while ($p->isRunning() ) {usleep($wait );}if ( !$p->isSuccessful() ) {break;}}while (true );$is_started =$p->isStarted();$is_running =$p->isRunning();$exit_code  =$p->getExitCode();echosprintf('Started: %s, Running: %s, Exit code: %s',$is_started,$is_running,$exit_code ) .PHP_EOL;

Impact:

  • This change only affects Symfony applications running on PHP versions below 8.3.
  • It improves the reliability of process status reporting in these environments.
  • No breaking changes or backward compatibility issues are introduced.

Testing:

I haven't added tests to this PR because:

  • This bug involves racing conditions, which is hard to replicate.
  • It's past 1 AM local time right now, and I've been debugging this for the past 6 hours.
  • The provided "Proof of Concept" can serve as an initial check to confirm the bug.

I'm really not the type of developer that does not write tests, but I beg my pardon for the reasons above.

Considerations

  • Based on theproc_open implementation, this fix might not be needed on Windows.
  • You can find additional context for this bug in thisStack Overflow answer.

@carsonbot
Copy link

Hey!

I see that this is your first PR. That is great! Welcome!

Symfony has acontribution guide which I suggest you to read.

In short:

  • Always add tests
  • Keep backward compatibility (seehttps://symfony.com/bc).
  • Bug fixes must be submitted against the lowest maintained branch where they apply (seehttps://symfony.com/releases)
  • Features and deprecations must be submitted against the 7.1 branch.

Review the GitHub status checks of your pull request and try to solve the reported issues. If some tests are failing, try to see if they are failing because of this change.

When two Symfony core team members approve this change, it will be merged and you will become an official Symfony contributor!
If this PR is merged in a lower version branch, it will be merged up to all maintained branches within a few days.

I am going to sit back now and wait for the reviews.

Cheers!

Carsonbot

@carsonbot
Copy link

Hey!

Thanks for your PR. You are targeting branch "7.1" but it seems your PR description refers to branch "5.4, 6.4, 7.0".
Could you update the PR description or change target branch? This helps core maintainers a lot.

Cheers!

Carsonbot

@Luc45Luc45 changed the base branch from7.1 to5.4February 7, 2024 03:41
@Luc45Luc45 changed the base branch from5.4 to7.1February 7, 2024 03:42
@Luc45
Copy link
ContributorAuthor

Closed in favor of#53821 due to wrong base branch

@Luc45Luc45 closed thisFeb 7, 2024
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@lyrixxlyrixxAwaiting requested review from lyrixx

@ycerutoycerutoAwaiting requested review from yceruto

@chalasrchalasrAwaiting requested review from chalasr

@dunglasdunglasAwaiting requested review from dunglas

@xabbuhxabbuhAwaiting requested review from xabbuh

Assignees

No one assigned

Projects

None yet

Milestone

7.1

Development

Successfully merging this pull request may close these issues.

2 participants

@Luc45@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp