Skip to content

Commit 350a15c

Browse files
authored
Merge pull request #85 from neo4j-php/long-query-fixes
Long query fixes
2 parents 1efed4b + 95e11ea commit 350a15c

File tree

5 files changed

+20
-5
lines changed

5 files changed

+20
-5
lines changed

.github/workflows/db-tests.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ jobs:
2020
image: neo4j:${{ matrix.neo4j-version }}
2121
env:
2222
NEO4J_AUTH: neo4j/nothing
23+
NEO4JLABS_PLUGINS: '["apoc"]'
2324
ports:
2425
- 7687:7687
2526
- 7474:7474

src/connection/Socket.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,8 @@ private function throwConnectException(): void
153153
if ($timediff >= $this->timeout) {
154154
throw ConnectionTimeoutException::createFromTimeout($this->timeout);
155155
}
156+
} else if ($code !== 0) {
157+
throw new ConnectException(socket_strerror($code), $code);
156158
}
157-
throw new ConnectException(socket_strerror($code), $code);
158159
}
159160
}

src/connection/StreamSocket.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,6 @@ public function read(int $length = 2048): string
100100
if (stream_get_meta_data($this->stream)["timed_out"])
101101
throw ConnectionTimeoutException::createFromTimeout($this->timeout);
102102

103-
if (empty($res))
104-
throw new ConnectException('Read error');
105-
106103
if (Bolt::$debug)
107104
$this->printHex($res, false);
108105

src/protocol/AProtocol.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ protected function read(?int &$signature)
7171
$msg = '';
7272
while (true) {
7373
$header = $this->connection->read(2);
74-
if (ord($header[0]) == 0x00 && ord($header[1]) == 0x00)
74+
if ($msg !== '' && ord($header[0]) == 0x00 && ord($header[1]) == 0x00)
7575
break;
7676
$length = unpack('n', $header)[1] ?? 0;
7777
$msg .= $this->connection->read($length);

tests/connection/AConnectionTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,22 @@ public function testMillisecondTimeout(string $alias): void
4545
}
4646
}
4747

48+
49+
/**
50+
* @dataProvider provideConnections
51+
*
52+
* @doesNotPerformAssertions
53+
*/
54+
public function testLongNoTimeout(string $alias): void
55+
{
56+
$socket = $this->getConnection($alias);
57+
$protocol = (new Bolt($socket))->build();
58+
$socket->setTimeout(200);
59+
$protocol->init(Auth::basic($GLOBALS['NEO_USER'], $GLOBALS['NEO_PASS']));
60+
61+
$protocol->run('CALL apoc.util.sleep(150000)', [], ['tx_timeout' => 150000]);
62+
}
63+
4864
/**
4965
* @dataProvider provideConnections
5066
*/

0 commit comments

Comments
 (0)