Skip to content

BlockingFile operations after destructor run throw TypeErrors #85

@bwoebi

Description

@bwoebi
PHP Fatal error:  Uncaught TypeError: fseek(): supplied resource is not a valid stream resource in /.../vendor/amphp/file/src/Driver/BlockingFile.php:184
Stack trace:
#0 /.../vendor/amphp/file/src/Driver/BlockingFile.php(184): fseek(Resource id #383, 0, 0)
#1 ...: Amp\File\Driver\BlockingFile->seek(0)

The cycle collector happened to first destroy the BlockingFile instance, then another class wanting to write to it in its destructor.
The fix would be trivial to just also set the handle to null in __destruct. Having it then emit a normal ClosedException.

I'm wondering though, do we really need an explicit fclose() call in BlockingFile destructor, and can't just have it automatically close whenever PHP frees the underlying resource? So that we can just continue using it...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions