Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when copying file to file #18

Open
seregazhuk opened this issue Feb 19, 2018 · 8 comments
Open

Error when copying file to file #18

seregazhuk opened this issue Feb 19, 2018 · 8 comments

Comments

@seregazhuk
Copy link
Contributor

seregazhuk commented Feb 19, 2018

I've tried to run this example with copying one file to another. It fails with:

Notice: Undefined offset: 1 in vendor/react/filesystem/src/ChildProcess/Adapter.php on line 225

I thinks this happens because we try to close() destination file twice. The first attempt happens here, when are done with reading:

$readStream->on('end', function () use ($deferred, $writeStream, &$writePromises) {
\React\Promise\all($writePromises)->then(function ()use ($deferred, $writeStream) {
$writeStream->end();
$deferred->resolve();
});
});

We call end() which implicitly closes the file.

And then in always() handler:

})->always(function () use ($node) {
$node->close();
});

We again try to close the same file and it fails. Should this always handler be removed or there is another solution?

@hotrush
Copy link

hotrush commented Aug 27, 2018

Have the same bug with child process adapter, happens randomly when writing lot of files, but data written correctly.

@WyriHaximus
Copy link
Member

What version are you on @hotrush? We released v0.1.1 two weeks a go which contains a lot of bug fixes.

@hotrush
Copy link

hotrush commented Aug 27, 2018

I'm on latest v0.1.1

@WyriHaximus
Copy link
Member

Same as @seregazhuk when you use the example it fails?

@hotrush
Copy link

hotrush commented Aug 28, 2018

@WyriHaximus my snippet is some different, i am using it with periodic timer

<?php

require __DIR__ . '/vendor/autoload.php';
$loop = \React\EventLoop\Factory::create();

$contents = '123';

$adapter = new \React\Filesystem\ChildProcess\Adapter($loop);
$filesystem = \React\Filesystem\Filesystem::createFromAdapter($adapter);
echo 'Using ', get_class($filesystem->getAdapter()), PHP_EOL;

$j = 0;

$loop->addPeriodicTimer(1, function () use ($filesystem, $contents, &$j) {
    for ($i = $j; $i <= $j+9; $i++) {
        $filename = __DIR__ . '/data/test/'.$i.'.txt';
        $filesystem->file($filename)->putContents($contents)->then(function () use ($filename) {
            echo $filename.' written'.PHP_EOL;
        }, function (Exception $e) {
            echo $e->getMessage(), PHP_EOL;
            echo $e->getTraceAsString(), PHP_EOL;
        });
    }
    $j += 10;
});

$loop->run();
vagrant@jessie:~/test$ php test.php 
Using React\Filesystem\ChildProcess\Adapter
/home/vagrant/test/data/test/0.txt written
/home/vagrant/test/data/test/1.txt written
/home/vagrant/test/data/test/2.txt written
/home/vagrant/test/data/test/4.txt written
/home/vagrant/test/data/test/3.txt written
/home/vagrant/test/data/test/5.txt written
/home/vagrant/test/data/test/6.txt written
/home/vagrant/test/data/test/8.txt written
PHP Notice:  Undefined offset: 1 in /home/vagrant/test/vendor/react/filesystem/src/ChildProcess/Adapter.php on line 219
/home/vagrant/test/data/test/9.txt written
/home/vagrant/test/data/test/10.txt written
/home/vagrant/test/data/test/13.txt written
/home/vagrant/test/data/test/11.txt written
/home/vagrant/test/data/test/12.txt written
/home/vagrant/test/data/test/14.txt written
/home/vagrant/test/data/test/15.txt written
/home/vagrant/test/data/test/16.txt written
/home/vagrant/test/data/test/18.txt written
/home/vagrant/test/data/test/17.txt written
/home/vagrant/test/data/test/19.txt written
/home/vagrant/test/data/test/20.txt written
/home/vagrant/test/data/test/23.txt written
/home/vagrant/test/data/test/21.txt written
/home/vagrant/test/data/test/22.txt written
/home/vagrant/test/data/test/24.txt written
/home/vagrant/test/data/test/26.txt written
/home/vagrant/test/data/test/25.txt written
/home/vagrant/test/data/test/28.txt written
/home/vagrant/test/data/test/27.txt written
/home/vagrant/test/data/test/29.txt written
/home/vagrant/test/data/test/31.txt written
/home/vagrant/test/data/test/30.txt written
/home/vagrant/test/data/test/33.txt written
/home/vagrant/test/data/test/32.txt written
/home/vagrant/test/data/test/34.txt written
/home/vagrant/test/data/test/35.txt written
/home/vagrant/test/data/test/37.txt written
/home/vagrant/test/data/test/36.txt written
/home/vagrant/test/data/test/38.txt written
/home/vagrant/test/data/test/39.txt written
/home/vagrant/test/data/test/40.txt written
/home/vagrant/test/data/test/41.txt written
/home/vagrant/test/data/test/43.txt written
/home/vagrant/test/data/test/42.txt written
/home/vagrant/test/data/test/44.txt written
/home/vagrant/test/data/test/45.txt written
/home/vagrant/test/data/test/47.txt written
/home/vagrant/test/data/test/46.txt written
/home/vagrant/test/data/test/49.txt written
/home/vagrant/test/data/test/48.txt written
/home/vagrant/test/data/test/50.txt written
/home/vagrant/test/data/test/51.txt written
/home/vagrant/test/data/test/52.txt written
/home/vagrant/test/data/test/53.txt written
/home/vagrant/test/data/test/54.txt written
/home/vagrant/test/data/test/55.txt written
PHP Notice:  Undefined offset: 1 in /home/vagrant/test/vendor/react/filesystem/src/ChildProcess/Adapter.php on line 219
/home/vagrant/test/data/test/56.txt written
/home/vagrant/test/data/test/58.txt written
/home/vagrant/test/data/test/59.txt written
/home/vagrant/test/data/test/60.txt written
/home/vagrant/test/data/test/61.txt written
/home/vagrant/test/data/test/62.txt written
PHP Notice:  Undefined offset: 2 in /home/vagrant/test/vendor/react/filesystem/src/ChildProcess/Adapter.php on line 219
/home/vagrant/test/data/test/63.txt written
/home/vagrant/test/data/test/65.txt written
/home/vagrant/test/data/test/66.txt written
/home/vagrant/test/data/test/68.txt written
/home/vagrant/test/data/test/67.txt written
/home/vagrant/test/data/test/69.txt written
/home/vagrant/test/data/test/71.txt written
/home/vagrant/test/data/test/70.txt written
PHP Notice:  Undefined offset: 1 in /home/vagrant/test/vendor/react/filesystem/src/ChildProcess/Adapter.php on line 219
/home/vagrant/test/data/test/73.txt written
/home/vagrant/test/data/test/75.txt written
/home/vagrant/test/data/test/74.txt written
/home/vagrant/test/data/test/77.txt written
/home/vagrant/test/data/test/78.txt written
/home/vagrant/test/data/test/79.txt written
/home/vagrant/test/data/test/76.txt written
^C

@seregazhuk
Copy link
Contributor Author

I cannot reproduce my issue with a new version v0.1.1 👌

@WyriHaximus
Copy link
Member

@hotrush thanks, will go over it soon and see where things have to be improved.
@seregazhuk great to hear!

@mmoreram
Copy link

I still have this issue. Do you have any updates?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants