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

Not enough data in buffer #123

Closed
yanmandev opened this issue Aug 23, 2020 · 8 comments
Closed

Not enough data in buffer #123

yanmandev opened this issue Aug 23, 2020 · 8 comments

Comments

@yanmandev
Copy link

This error occurs periodically in the file Buffer.php
Any ideas how I can solve it?

In Buffer.php line 56:
Not enough data in buffer to read 1 bytes

@clue
Copy link
Contributor

clue commented Aug 23, 2020

@yanmandev Thanks for reporting, this shouldn't have happened!

Unfortunately, we can not currently reproduce the problem you're seeing. Can you give us some more details about when this problem occurs and how this can be reproduced? Which platform are you using etc.?

@yanmandev
Copy link
Author

yanmandev commented Aug 24, 2020

My project runs on digitalocen servers (4 GB Memory / 80 GB Disk / FRA1 - Ubuntu 18.04.3 (LTS) x64). Mysql version 5.7.31.
It is difficult for me to reproduce the problem, but it occurs periodically after some time while the script is running.
Only restarting the script helps - supersvisor restart all.

PHP Fatal error:  Uncaught LogicException: Not enough data in buffer to read 1 bytes in /var/www/etherra-auction/backend/vendor/react/mysql/src/Io/Buffer.php:56
Stack trace:
#0 /var/www/etherra-auction/backend/vendor/react/mysql/src/Io/Buffer.php(115): React\MySQL\Io\Buffer->read()
#1 /var/www/etherra-auction/backend/vendor/react/mysql/src/Io/Buffer.php(168): React\MySQL\Io\Buffer->readInt1()
#2 /var/www/etherra-auction/backend/vendor/react/mysql/src/Io/Buffer.php(192): React\MySQL\Io\Buffer->readIntLen()
#3 /var/www/etherra-auction/backend/vendor/react/mysql/src/Io/Parser.php(260): React\MySQL\Io\Buffer->readStringLen()
#4 /var/www/etherra-auction/backend/vendor/evenement/evenement/src/Evenement/EventEmitterTrait.php(123): React\MySQL\Io\Parser->parse()
#5 /var/www/etherra-auction/backend/vendor/react/stream/src/Util.php(71): Evenement\EventEmitter->emit()
#6 /var/www/etherra-auction/backend/vendor/evenement/evenement/src/Evenement/EventEmitterTrait.php(123): React\Stream\Util::React\Stream\{closure}()
#7 /var/www/etherra-auc in /var/www/etherra-auction/backend/vendor/react/mysql/src/Io/Buffer.php on line 56

@clue
Copy link
Contributor

clue commented Aug 25, 2020

I'm still hoping for a simplified script to reproduce this.

I've personally been running this project in production for years and we're not aware of any such issues.

If you can help us pinpoint any issues, I'm happy to take a look. In the meantime, I'm not sure there's much we can do unfortunately.

@clue
Copy link
Contributor

clue commented Apr 19, 2021

Closing this due to a lack of feedback, as we can not reproduce this. Please come back with more details if this problem persists and we can reopen this 👍

@clue clue closed this as completed Apr 19, 2021
@pfk84
Copy link

pfk84 commented Aug 17, 2022

Just ran into the same issue (running with Framework X):

Not enough data in buffer to read 55 bytes

This only occurs if a certain sequence of queries is sent. If I restart the server in between, the affected query runs ok. I'm accessing the repository with the affected query from different controllers and then it breaks. If I access it multiple times from the same controller, all is ok.

Another strange thing is if I complicate the query a bit, the query just never returns and the whole connection is stuck instead of throwing the above mentioned error message.

The query itself is very basic and I can't see anything wrong with it at all. If I always use a new db connection, all is fine. So I'd assume some internal state gets messed up on certain occasions.

@pfk84
Copy link

pfk84 commented Aug 19, 2022

Small update: To me it looks like that some packets stay in the buffer even after queries are completed (like EOF_Packet). When new packets arrive, these old packets get interpreted first but the state does not match (e.g. interpreted as result set instead of header).

I found that in the function onResultDone() in Parser.php:296 $command->emit('end'); is run before the state is reset (resultFields and rsState) - if I do this before emitting end, all works for me. Don't know if this fix is correct, though...

@pfk84
Copy link

pfk84 commented Aug 19, 2022

Looks like I was using Fibers wrong (shout-out to @clue) and this caused the issue, so from my side all is ok now.

@clue
Copy link
Contributor

clue commented Aug 20, 2022

I've helped @pfk84 to debug the error above and could eventually track this down to an incorrect usage of reactphp/async and not an error in this MySQL implementation. The problem boiled down to calling await($db->query($sql)) from within a promise callback like $promise->then($fn). The subtle error is that await() is blocking and must not be called from within a promise callback, so this needs to be wrapped in a $promise->then(async($fn)) to make this work. The error messages where somewhat misleading and unhelpful, so the conclusion here is to improve error reporting for incorrect fiber usage as discussed in reactphp/async#50.

Along the way, I've also spent a fair amount of time analyzing the MySQL parser and could indeed find a problem that turned out to be unrelated to @pfk84's error but could potentially have caused @yanmandev's original report. I've filed #158 to fix this issue. Together with this analysis, you're looking at ~8 hours of work, enjoy!

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

No branches or pull requests

3 participants