-
-
Notifications
You must be signed in to change notification settings - Fork 25
Description
Hi, I think I'm having an issue with openFile
.
First of all here's a reproduction: https://github.com/tncrazvan/amphp-file-parallel-driver-issue-reproduction
The program is a web server and it's serving a web application to the client.
However when sending many requests in a row and canceling them (you can reproduce this by refreshing the browser very fast) I get this error in the console:
PHP Fatal error: Uncaught UnexpectedValueException: Object not found in /home/raz/GitHub/tncrazvan/amphp-file-reproduction-SplObjectStorage-issue/vendor/amphp/file/src/Driver/ParallelFilesystemDriver.php:49
Stack trace:
#0 /home/raz/GitHub/tncrazvan/amphp-file-reproduction-SplObjectStorage-issue/vendor/amphp/file/src/Internal/FileWorker.php(26): Amp\File\Driver\ParallelFilesystemDriver::Amp\File\Driver\{closure}()
#1 [internal function]: Amp\File\Internal\FileWorker->__destruct()
#2 {main}
Next Error: Cannot use object of type SplObjectStorage as array in /home/raz/GitHub/tncrazvan/amphp-file-reproduction-SplObjectStorage-issue/vendor/amphp/file/src/Driver/ParallelFilesystemDriver.php:49
Stack trace:
#0 /home/raz/GitHub/tncrazvan/amphp-file-reproduction-SplObjectStorage-issue/vendor/amphp/file/src/Internal/FileWorker.php(26): Amp\File\Driver\ParallelFilesystemDriver::Amp\File\Driver\{closure}()
#1 [internal function]: Amp\File\Internal\FileWorker->__destruct()
#2 {main}
thrown in /home/raz/GitHub/tncrazvan/amphp-file-reproduction-SplObjectStorage-issue/vendor/amphp/file/src/Driver/ParallelFilesystemDriver.php on line 49
Note
The error is only visible after closing the program (ctrl+c).
The problem seems to be this assert.
I think I'm doing something wrong but I'm not sure exactly what.
It's probably too much to ask for a solution because there's a lot of code behind my use case.
I was wondering if you have any ideas as to what is causing that worker to disappear from the storage.
It's a bit difficult to debug because the problem doesn't seem to happen at all while running with xdebug, it just works fine when running with xdebug for some reason.
My first instinct tells me it's somewhat related to timing and xdebug slows the application enough to the point where the worker doesn't get detached at the wrong time?
Other notes
-
My whole application is wrapped in one single
async(...)->await();
You can see that by following Bootstrap::start.
-
Other than
openFile
and the amp http server, there are no other async operations in the application going on.
However, I am trying serve the client byte range responses when possible.
Which is this piece of code here.
It's nothing fancy, it just reads the range header and throws the exception if it's invalid and falls back to streaming the file as usual.