You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Code working on *nix silently failing on Windows #155
Otherwise it silently failed and the loop stopped without writing that file.
Is there anything I could change in the original code with pipe() that would make this work?
Is there an edge case that would make the previous or current logic not work as expected? I followed some examples but I'm not sure about the code, for me it seems there should be some call like "wait for this stream to end before continuing", but maybe it's fine :)
And 3. Am I missing some error handling in my code so that I'd know about this error before continuing with the execution? I tried the 'error' event on $body but it wasn't called.
To reproduce, check out the previous commit before the fix (phpstan/phpstan-src@2d8dcd1) and run vendor/bin/phing phpstan-pro on Windows. You should get "PHAR signature corrupted" error message. Which means the file is incomplete or doesn't exist at all...
I don't have any knowledge of ReactPHP internals sadly, but I'd say that if this works (phpstan/phpstan-src@8a7ae4f), it should be possible using the Stream's pipe method too :) File writing is blocking in any case and on any platform anyway...
But I'd be happy with just getting an error with the original code on Windows, the pipe method doesn't have to work, but silent failure is not ideal...
@ondrejmirtes Thanks for bringing this up, this is an interesting one!
It looks like you're seeing a combination of multiple things at play here:
Windows doesn't support non-blocking I/O on filesystem handles. If you pass a file handle to WritableResourceStream, it will throw an RuntimeException as detailed in Enforce using non-blocking I/O #46. The suggested alternative would be to use reactphp/filesystem as also pointed out in the documentation.
This happens within a promise callback function which would automatically reject this promise. Until Detecting unhandled rejections promise#87 is addressed (which is a major BC break due for the next major promise version), it will discard this error message unless you add some error reporting manually.
This combined means it looks like it's silently failing, which is definitely not desired. We're working on a fix in the above tickets, in the meantime you can always keep using your current work around. Note that you're using blocking filesystem I/O, but it's probably acceptable if you have little concurrency (think downloading hundreds of files at once).
I believe this has been answered, so I'm closing this for now. Please come back with more details if this problem persists and we can always reopen this 👍
Activity
ondrejmirtes commentedon Sep 26, 2020
And 3. Am I missing some error handling in my code so that I'd know about this error before continuing with the execution? I tried the 'error' event on $body but it wasn't called.
WyriHaximus commentedon Sep 27, 2020
What kind of windows are we talking about? WSL2, or directly raw on Windows?
ondrejmirtes commentedon Sep 27, 2020
Directly on Windows, using Git Bash or Windows Terminal.
ondrejmirtes commentedon Sep 27, 2020
To reproduce, check out the previous commit before the fix (phpstan/phpstan-src@2d8dcd1) and run
vendor/bin/phing phpstan-proon Windows. You should get "PHAR signature corrupted" error message. Which means the file is incomplete or doesn't exist at all...On Linux and Mac it successfully finishes.
WyriHaximus commentedon Sep 27, 2020
Will try later, but IIRC there is something about Windows native streams that makes this an issue :(
ondrejmirtes commentedon Sep 27, 2020
I don't have any knowledge of ReactPHP internals sadly, but I'd say that if this works (phpstan/phpstan-src@8a7ae4f), it should be possible using the Stream's
pipemethod too :) File writing is blocking in any case and on any platform anyway...ondrejmirtes commentedon Sep 27, 2020
But I'd be happy with just getting an error with the original code on Windows, the
pipemethod doesn't have to work, but silent failure is not ideal...WyriHaximus commentedon Sep 27, 2020
This is a Windows internals issue, and I'm not sure if there is an error. But I'll have a look
clue commentedon Jan 25, 2021
@ondrejmirtes Thanks for bringing this up, this is an interesting one!
It looks like you're seeing a combination of multiple things at play here:
WritableResourceStream, it will throw anRuntimeExceptionas detailed in Enforce using non-blocking I/O #46. The suggested alternative would be to use reactphp/filesystem as also pointed out in the documentation.This combined means it looks like it's silently failing, which is definitely not desired. We're working on a fix in the above tickets, in the meantime you can always keep using your current work around. Note that you're using blocking filesystem I/O, but it's probably acceptable if you have little concurrency (think downloading hundreds of files at once).
I believe this has been answered, so I'm closing this for now. Please come back with more details if this problem persists and we can always reopen this 👍
ondrejmirtes commentedon Jan 25, 2021
Thank you!