neo4j-php / Bolt

PHP library to provide connectivity to graph database over TCP socket with Bolt specification
https://packagist.org/packages/stefanak-michal/bolt
MIT License
73 stars 10 forks source link

Long query fixes #85

Closed transistive closed 2 years ago

transistive commented 2 years ago

When running queries over 120 seconds, the sockets will read an empty string, leading to cryptic errors: https://github.com/neo4j-php/neo4j-php-client/issues/102

To solve this, I had to remove the assumption that empty strings result in a read error, and continue reading if a chunking symbol 0x00 0x00 appeared when no message has been read yet.

According to the tests, everything still works

stefanak-michal commented 2 years ago

If you have problem with receiving data from server. Can it happen you will get only a part of chunk? what about something like this?

$msg = '';
while (true) {
  $header = $this->connection->read(2);
  $length = unpack('n', $header)[1] ?? 0; //because 0x00 0x00 end mark is chunk of size 0

  if ($length > 0) {
    $chunk = '';
    $size = mb_strlen($chunk, '8bit');
    while ($size < $length) {
      $chunk .= $this->connection->read($length - $size);
    }
    $msg .= $chunk;
  } else {
    break;
  }
}

not tested.. written in this comment.

transistive commented 2 years ago

It looks a bit better, but I will have to test it. I am currently working on something else, but will circle back to it later today or tomorrow.

stefanak-michal commented 2 years ago

@transistive I can try to update it but I will have time next week. Also I'm thinking about checking if reading header has returned length 2. Right now if it works for you ok, I'll make issue and check it next week.

transistive commented 2 years ago

Sounds like a great plan. Are you willing to release it in a minor version in the meantime or shall we wait?

stefanak-michal commented 2 years ago

if you need it we can make release

transistive commented 2 years ago

It would be nice to have so I can include it the release of the client which I have planned for the weekend