Repository navigation
Reading a file throws error or hangs #5
Copy link
Copy link
Open
Description
With the following code:
<?php
require "vendor/autoload.php";
$loop = \React\EventLoop\Factory::create();
$filesystem = \React\Filesystem\Filesystem::create($loop);
$loaded = [];
// I have "big_file_5.txt" and "big_file_7.txt".
// Both with about 6 MB.
foreach (['5', '7'] as $num) {
$filename = __DIR__.'/resources/big_file_'.$num.'.txt';
$file = $filesystem->file($filename);
$file->getContents()->then(
function ($content) use ($filename, &$loaded) {
echo "Got contents of $filename\n";
$loaded[] = $content;
},
function ($error) use ($filename, &$loaded) {
echo "Error when reading $filename\n";
echo $error;
}
);
}
$loop->addPeriodicTimer(1, function () use (&$loaded) {
echo count($loaded)." loaded files\n";
echo "tick-tack\n";
});
echo "Running. Press CTRL+C to exit\n";
$loop->run();The output should be something along the lines of:
$ php main.php
Running. Press CTRL+C to exit
Got contents of <project_path>/resources/big_file_7.txt
Got contents of <project_path>/resources/big_file_5.txt
2 loaded files
tick-tack
2 loaded files
tick-tack
2 loaded files
tick-tack
2 loaded files
tick-tack
^C
But sometimes the Eio throws an unknown error
$ php main.php
Running. Press CTRL+C to exit
Error when reading <project_path>/resources/big_file_7.txt
exception 'React\Filesystem\Eio\RuntimeException' with message 'Unknown error calling "eio_open"' in <project_path>/vendor/react/filesystem/src/EioAdapter.php:280
Stack trace:
#0 <project_path>/vendor/react/filesystem/src/EioAdapter.php(254): React\Filesystem\EioAdapter->executeDelayedCall('eio_open', Array, -1, Object(React\Promise\Deferred))
#1 [internal function]: React\Filesystem\EioAdapter->React\Filesystem\{closure}(Object(React\EventLoop\LibEventLoop))
#2 <project_path>/vendor/react/event-loop/Tick/FutureTickQueue.php(46): call_user_func(Object(Closure), Object(React\EventLoop\LibEventLoop))
#3 <project_path>/vendor/react/event-loop/LibEventLoop.php(202): React\EventLoop\Tick\FutureTickQueue->tick-tack()
#4 <project_path>/main.php(32): React\EventLoop\LibEventLoop->run()
#5 {main}Got contents of <project_path>/resources/big_file_5.txt
1 loaded files
tick-tack
1 loaded files
tick-tack
^C
Or one or both reads hangs forever
Running. Press CTRL+C to exit
Got contents of <project_path>/resources/big_file_7.txt
1 loaded files
tick-tack
1 loaded files
tick-tack
1 loaded files
tick-tack
1 loaded files
tick-tack
1 loaded files
tick-tack
1 loaded files
tick-tack
1 loaded files
tick-tack
1 loaded files
tick-tack
1 loaded files
tick-tack
1 loaded files
tick-tack
1 loaded files
tick-tack
... (forever)
Every time I run the script I got one of the results randomly(?). I'm running Ubuntu 14.04.1 LTS.
@WyriHaximus, do you have an idea of what may be causing the problem?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
Activity
[-]Sometimes the reading of a file simply hangs[/-][+]Reading a file throws error or hangs[/+]WyriHaximus commentedon Apr 23, 2015
Hmm interesting, I'll take a look at his, I've seen odd behavior with reading multiple files at the same time before but never tried to nail it down before because it occurred randomly. I'll give this code a shot locally and see what happens 👍 .
digitv commentedon Apr 26, 2018
Hello @WyriHaximus !
I have same issue with file reading, maybe you need to add other listener to the 'end' event on stream in
FileInterface::getContentsfunction. Like this solution:WyriHaximus commentedon Apr 26, 2018
IIRC I fixed this locally but was hunting down some other errors popping up. I'll try to work on this during the weekend.
digitv commentedon Apr 26, 2018
This can be also an issue from React\Promise\Stream::buffer function, there is no handling of 'end' event and that is strange ^_^
WyriHaximus commentedon Apr 26, 2018
FYI my WIP changes: master...WyriHaximus-labs:fix-test-chown-uid
digitv commentedon Apr 26, 2018
Thanks a lot, will use as temporary solution up to next update 😃
WyriHaximus commentedon Apr 29, 2018
Got a bit further, everything runs without issues on PHP 5 and 7 locally. So I'm currently debugging permission issues on travis
WyriHaximus commentedon May 13, 2018
Nearly fixed all issues: https://travis-ci.org/WyriHaximus-labs/filesystem/builds/378239247
Once done I'll file a bunch of PR's for all fixes 🎉
WyriHaximus commentedon May 27, 2018
Gave up and marked
5.4as allowed failure. Will start creating PR's for all fixes tomorrowWyriHaximus commentedon May 28, 2018
Right so PR #23, #24, #25, #26, #27, #28, #29, #30, and #31 filed 🎉