Skip to content

[Process] Avoid calling fclose on an already closed resource #45103

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 24, 2022

Conversation

Seldaek
Copy link
Member

@Seldaek Seldaek commented Jan 21, 2022

Q A
Branch? 4.4
Bug fix? yes
New feature? no
Deprecations? no
Tickets Fix #...
License MIT
Doc PR symfony/symfony-docs#...

I got this in Composer while interrupting an install process with Ctrl-C.

PHP Fatal error:  Uncaught TypeError: fclose(): supplied resource is not a valid stream resource in /var/www/composer/vendor/symfony/process/Pipes/AbstractPipes.php:50
Stack trace:
#0 /var/www/composer/vendor/symfony/process/Pipes/AbstractPipes.php(50): fclose()
#1 /var/www/composer/vendor/symfony/process/Pipes/UnixPipes.php(50): Symfony\Component\Process\Pipes\AbstractPipes->close()
#2 [internal function]: Symfony\Component\Process\Pipes\UnixPipes->__destruct()
#3 {main}
  thrown in /var/www/composer/vendor/symfony/process/Pipes/AbstractPipes.php on line 50

I am assuming it's due to a process which was not closed properly, which is very likely given we run a bunch of them concurrently.. It's pretty hard to debug as it's also hard to reproduce, so I am not sure what to do except handle this case gracefully in the close/__destruct function and hope that at least lets it clean up processes without crashing this way.

@carsonbot carsonbot added this to the 4.4 milestone Jan 21, 2022
@Seldaek Seldaek changed the title Avoid calling fclose on an already closed resource [Process] Avoid calling fclose on an already closed resource Jan 21, 2022
@@ -47,7 +47,9 @@ public function __construct($input)
public function close()
{
foreach ($this->pipes as $pipe) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's remove the foreach completly, php will cleanup handles automatically

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not removing foreach completely then?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not being too smart is usually safer :P

@nicolas-grekas
Copy link
Member

Thank you @Seldaek.

@nicolas-grekas nicolas-grekas merged commit 859d4a1 into symfony:4.4 Jan 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants