Skip to content

Commit c9e8b6b

Browse files
committed
correctly propagate tx_timeout
1 parent c5cf687 commit c9e8b6b

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

src/Bolt/Session.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,9 @@ private function beginInstantTransaction(
160160
private function acquireConnection(TransactionConfiguration $config, SessionConfiguration $sessionConfig): BoltConnection
161161
{
162162
$connection = $this->pool->acquire($this->uri, $this->auth, $sessionConfig);
163-
$connection->setTimeout($config->getTimeout());
163+
// We try and let the server do the timeout management.
164+
// Since the client should not run indefinitely, we just multiply the client side by two, just in case
165+
$connection->setTimeout($config->getTimeout() * 2);
164166

165167
return $connection;
166168
}

tests/Integration/ComplexQueryTest.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,52 @@ public function testLongQueryUnmanaged(string $alias): void
376376
$tsx->run('CALL apoc.util.sleep(10000)');
377377
}
378378

379+
/**
380+
* @dataProvider connectionAliases
381+
*/
382+
public function testSimpleTimeout(string $alias): void
383+
{
384+
if (str_starts_with($alias, 'http')) {
385+
self::markTestSkipped('Http does not support timeouts at the moment');
386+
}
387+
388+
try {
389+
$this->getClient()
390+
->getDriver($alias)
391+
->createSession()
392+
->run(
393+
"MATCH (n:Node) SET n.testing = 'hello' WITH * CALL apoc.util.sleep(2000000)",
394+
[],
395+
TransactionConfiguration::default()->withTimeout(10)
396+
);
397+
} catch (Neo4jException $e) {
398+
self::assertEquals('Neo.ClientError.Transaction.TransactionTimedOut', $e->getNeo4jCode());
399+
}
400+
}
401+
402+
/**
403+
* @dataProvider connectionAliases
404+
*/
405+
public function testDiscardAfterTimeout(string $alias): void
406+
{
407+
if (str_starts_with($alias, 'http')) {
408+
self::markTestSkipped('Http does not support timeouts at the moment');
409+
}
410+
411+
$this->expectException(Neo4jException::class);
412+
413+
$result = $this->getClient()
414+
->getDriver($alias)
415+
->createSession()
416+
->run(
417+
"MATCH (n:Node) SET n.testing = 'hello' WITH * CALL apoc.util.sleep(2000000)",
418+
[],
419+
TransactionConfiguration::default()->withTimeout(150)
420+
);
421+
422+
unset($result);
423+
}
424+
379425
/**
380426
* @dataProvider connectionAliases
381427
*/

0 commit comments

Comments
 (0)