Skip to content

Commit

Permalink
Merge pull request #85 from neo4j-php/long-query-fixes
Browse files Browse the repository at this point in the history
Long query fixes
  • Loading branch information
transistive authored Mar 2, 2022
2 parents 1efed4b + 95e11ea commit 350a15c
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 5 deletions.
1 change: 1 addition & 0 deletions .github/workflows/db-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ jobs:
image: neo4j:${{ matrix.neo4j-version }}
env:
NEO4J_AUTH: neo4j/nothing
NEO4JLABS_PLUGINS: '["apoc"]'
ports:
- 7687:7687
- 7474:7474
Expand Down
3 changes: 2 additions & 1 deletion src/connection/Socket.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,8 @@ private function throwConnectException(): void
if ($timediff >= $this->timeout) {
throw ConnectionTimeoutException::createFromTimeout($this->timeout);
}
} else if ($code !== 0) {
throw new ConnectException(socket_strerror($code), $code);
}
throw new ConnectException(socket_strerror($code), $code);
}
}
3 changes: 0 additions & 3 deletions src/connection/StreamSocket.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,6 @@ public function read(int $length = 2048): string
if (stream_get_meta_data($this->stream)["timed_out"])
throw ConnectionTimeoutException::createFromTimeout($this->timeout);

if (empty($res))
throw new ConnectException('Read error');

if (Bolt::$debug)
$this->printHex($res, false);

Expand Down
2 changes: 1 addition & 1 deletion src/protocol/AProtocol.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ protected function read(?int &$signature)
$msg = '';
while (true) {
$header = $this->connection->read(2);
if (ord($header[0]) == 0x00 && ord($header[1]) == 0x00)
if ($msg !== '' && ord($header[0]) == 0x00 && ord($header[1]) == 0x00)
break;
$length = unpack('n', $header)[1] ?? 0;
$msg .= $this->connection->read($length);
Expand Down
16 changes: 16 additions & 0 deletions tests/connection/AConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,22 @@ public function testMillisecondTimeout(string $alias): void
}
}


/**
* @dataProvider provideConnections
*
* @doesNotPerformAssertions
*/
public function testLongNoTimeout(string $alias): void
{
$socket = $this->getConnection($alias);
$protocol = (new Bolt($socket))->build();
$socket->setTimeout(200);
$protocol->init(Auth::basic($GLOBALS['NEO_USER'], $GLOBALS['NEO_PASS']));

$protocol->run('CALL apoc.util.sleep(150000)', [], ['tx_timeout' => 150000]);
}

/**
* @dataProvider provideConnections
*/
Expand Down

0 comments on commit 350a15c

Please sign in to comment.