Skip to content

Commit 8e45076

Browse files
authored
#53 - cancel query before close connection (#54)
1 parent c3d2490 commit 8e45076

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/PgSqlHandle.php

+1
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ private function fetchTypes(string $id): Promise
195195
public function close(): void
196196
{
197197
if ($this->handle instanceof \PgSql\Connection || \is_resource($this->handle)) {
198+
\pg_cancel_query($this->handle);
198199
\pg_close($this->handle);
199200
$this->handle = null;
200201
}

test/AbstractConnectTest.php

+12
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,16 @@ public function testConnectInvalidUser(): Promise
6666

6767
return $this->connect(PostgresConnectionConfig::fromString('host=localhost user=invalid'), new TimeoutCancellationToken(100));
6868
}
69+
70+
public function testConnectionClose(): \Generator
71+
{
72+
$connection = yield $this->connect(PostgresConnectionConfig::fromString('host=localhost user=postgres'));
73+
$this->assertInstanceOf(Connection::class, $connection);
74+
75+
$connection->execute('SELECT pg_sleep(10)');
76+
77+
$start = microtime(true);
78+
$connection->close();
79+
$this->assertEquals(0, round(microtime(true) - $start));
80+
}
6981
}

0 commit comments

Comments
 (0)