Skip to content

Code working on *nix silently failing on Windows #155

Closed

Description

@ondrejmirtes

Probably related to: #133

I had to make this change for the code to also work on Windows: phpstan/phpstan-src@8a7ae4f

Otherwise it silently failed and the loop stopped without writing that file.

  1. Is there anything I could change in the original code with pipe() that would make this work?
  2. 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 :)

Thank you!

Activity

  1. ondrejmirtes commented on Sep 26, 2020

    @ondrejmirtes
    Author

    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.

  2. WyriHaximus commented on Sep 27, 2020

    @WyriHaximus
    Member

    What kind of windows are we talking about? WSL2, or directly raw on Windows?

  3. ondrejmirtes commented on Sep 27, 2020

    @ondrejmirtes
    Author

    Directly on Windows, using Git Bash or Windows Terminal.

  4. ondrejmirtes commented on Sep 27, 2020

    @ondrejmirtes
    Author

    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...

    On Linux and Mac it successfully finishes.

  5. WyriHaximus commented on Sep 27, 2020

    @WyriHaximus
    Member

    Will try later, but IIRC there is something about Windows native streams that makes this an issue :(

  6. ondrejmirtes commented on Sep 27, 2020

    @ondrejmirtes
    Author

    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...

  7. ondrejmirtes commented on Sep 27, 2020

    @ondrejmirtes
    Author

    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...

  8. WyriHaximus commented on Sep 27, 2020

    @WyriHaximus
    Member

    This is a Windows internals issue, and I'm not sure if there is an error. But I'll have a look

  9. clue commented on Jan 25, 2021

    @clue
    Member

    @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 👍

  10. ondrejmirtes commented on Jan 25, 2021

    @ondrejmirtes
    Author

    Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions