amphp / byte-stream

A non-blocking stream abstraction for PHP based on Amp.

Home Page:https://amphp.org/byte-stream

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Invalid packet received since update to byte-stream 1.2.4

ostrolucky opened this issue · comments

I've just released my application built on amphp at https://github.com/ostrolucky/stdinho Just before announcing it to world, I updated my dependencies. And it no longer works. Latest amphp/byte-stream it works with reliably is 1.2.2. 1.2.3 blocks in a way socket isn't created, 1.2.4 crashes with following error.

In ChannelParser.php line 61:
                                                                               
  [Amp\Parallel\Sync\ChannelException]                                         
  Invalid packet received: \xce\xb3\x1a\x1b\x1\xe1\xff\x9d\xf8]D\xfb\xbc\xf4\  
  xa8\xb6\xd8\xd6oH\x18\xff\x9a\xa\x98\xb3\xc9\x5t \x7f\x4\xed\xf\xa8\xbf\xc3  
  ?\x86{\xae\xd1\xd5\xbep\xa\xcc\xcbEIM;\xe9\x0\x95\xfb\x86\xebg\x3RwZ\x13\xa  
  6)Q|\x82y0\xa9\x86`\xc0\xd\x13\x82\xda\x99d\xcb\x9af\x9b\x81\xf1\xch\xd1\xa  
  e?\x3\xd0\x94&\\x1dVY\x3\xe1\xfc\xecK\x1dow\x15\xa1\x8a\x89n\xbc\x95t\xa6\x  
  f50\xf5";s:43:"\x0Amp\Parallel\Worker\Internal\TaskResult\x0id";s:2:"km";}   
                                                                               

Exception trace:
 Amp\Parallel\Sync\ChannelParser::parser() at n/a:n/a
 Generator->send() at /media/gadelat/sdata/GDrive/src/php/stdinho/vendor/amphp/parser/lib/Parser.php:102
 Amp\Parser\Parser->push() at /media/gadelat/sdata/GDrive/src/php/stdinho/vendor/amphp/parallel/lib/Sync/ChannelledStream.php:71
 Amp\Parallel\Sync\ChannelledStream->Amp\Parallel\Sync\{closure}() at n/a:n/a
 Generator->send() at /media/gadelat/sdata/GDrive/src/php/stdinho/vendor/amphp/amp/lib/Coroutine.php:74
 Amp\Coroutine->Amp\{closure}() at /media/gadelat/sdata/GDrive/src/php/stdinho/vendor/amphp/amp/lib/Internal/Placeholder.php:127
 class@anonymous\/media/gadelat/sdata/GDrive/src/php/stdinho/vendor/amphp/amp/lib/Deferred.php0x7f2c357fa2d3->resolve() at /media/gadelat/sdata/GDrive/src/php/stdinho/vendor/amphp/amp/lib/Deferred.php:41
 Amp\Deferred->resolve() at /media/gadelat/sdata/GDrive/src/php/stdinho/vendor/amphp/byte-stream/lib/ResourceInputStream.php:90
 Amp\ByteStream\ResourceInputStream::Amp\ByteStream\{closure}() at /media/gadelat/sdata/GDrive/src/php/stdinho/vendor/amphp/amp/lib/Loop/NativeDriver.php:172
 Amp\Loop\NativeDriver->selectStreams() at /media/gadelat/sdata/GDrive/src/php/stdinho/vendor/amphp/amp/lib/Loop/NativeDriver.php:68
 Amp\Loop\NativeDriver->dispatch() at /media/gadelat/sdata/GDrive/src/php/stdinho/vendor/amphp/amp/lib/Loop/Driver.php:130
 Amp\Loop\Driver->tick() at /media/gadelat/sdata/GDrive/src/php/stdinho/vendor/amphp/amp/lib/Loop/Driver.php:70
 Amp\Loop\Driver->run() at /media/gadelat/sdata/GDrive/src/php/stdinho/vendor/amphp/amp/lib/Loop.php:76
 Amp\Loop::run() at /media/gadelat/sdata/GDrive/src/php/stdinho/bin/stdinho:50
 Closure->{closure}() at n/a:n/a
 call_user_func() at /media/gadelat/sdata/GDrive/src/php/stdinho/vendor/symfony/console/Command/Command.php:250
 Symfony\Component\Console\Command\Command->run() at /media/gadelat/sdata/GDrive/src/php/stdinho/vendor/symfony/console/Application.php:865
 Symfony\Component\Console\Application->doRunCommand() at /media/gadelat/sdata/GDrive/src/php/stdinho/vendor/symfony/console/Application.php:241
 Symfony\Component\Console\Application->doRun() at /media/gadelat/sdata/GDrive/src/php/stdinho/vendor/symfony/console/Application.php:143
 Symfony\Component\Console\Application->run() at /media/gadelat/sdata/GDrive/src/php/stdinho/bin/stdinho:56

Codebase is simple, please clone it and try it. I have no idea where could be a problem. It can be reproduced by running following:

#terminal 1
$ head -c 1G </dev/urandom | bin/stdinho 127.0.0.1:1337 -v
#terminal 2
$ curl localhost:1337 > /dev/null

The error I get is a different one:

PHP Fatal error:  Uncaught Error: Call to a member function resolve() on null in /home/kelunik/GitHub/ostrolucky/stdinho/vendor/amphp/byte-stream/lib/ResourceInputStream.php:100

That other error I mentioned happened when the buffering completed before a client connected. Both are fixed now. Thanks!