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

Read error when writing big random data #60

Closed transistive closed 3 years ago

transistive commented 3 years ago

Describe the bug When creating parameters with random data, a standard read error appears. When testing big strings, it works flawlessly, but with big random data is crashes.

To Reproduce

$socket = new \Bolt\connection\StreamSocket('neo4j');
$neo = new \Bolt\Bolt($socket);
$neo->init('MyClient/1.0', 'neo4j', 'test');
$neo->begin();

$neo->run('MERGE (a:label {id:"xyz"})');

$params = [
    'id' => 'xyz',
];

while (true) {
    try {
        // show current length of parameters array
        echo strlen(serialize($params)).PHP_EOL;

        $check = $neo->run('MATCH (a :label {id:$id}) RETURN a', $params);

        $params[base64_encode(random_bytes(32))] = base64_encode(random_bytes(128));
    } catch (Exception $e) {
        echo $e;

        $neo->run('MATCH (a:label {id:"xyz"}) DELETE a');

        exit;
    }
}

Expected behaviour This script should be able to run for as long as the server or connection does not crash.

Desktop (please complete the following information):

Additional context This problem came to light from this issue in the client: https://github.com/neo4j-php/neo4j-php-client/issues/70.

stefanak-michal commented 3 years ago

just a small bug :) 350f252

stefanak-michal commented 3 years ago

https://github.com/neo4j-php/Bolt/releases/tag/v2.5.1

stefanak-michal commented 3 years ago

Btw it's really dangerous piece of code. After it was working I reached a moment when my computer started freezing and Neo4j crashed at memory.

transistive commented 3 years ago

Sorry about that. I received to code from the issue on the client library! Thank you for the quick fix, as always :)

in3rsha commented 3 years ago

Btw it's really dangerous piece of code. After it was working I reached a moment when my computer started freezing and Neo4j crashed at memory.

Sorry about that, I should have put in a break point when the array became large enough.

Thank you so much the fix (and so quickly). Been scratching my head over it for the last few days.

stefanak-michal commented 3 years ago

@transistive @in3rsha No big deal, no harm was done.

Always happy to help.