Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

reset connection state #101

Merged
merged 1 commit into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions asynch/pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ async def release(self, connection: Connection):
if self._closing:
await connection.close()
else:
connection._connection.reset_state()
self._free.append(connection)
fut = self._loop.create_task(self._wakeup())
return fut
Expand Down
32 changes: 32 additions & 0 deletions tests/test_pool.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import pytest
from socket import gaierror
from asyncio import gather

from asynch.connection import Connection

Expand Down Expand Up @@ -30,3 +32,33 @@ async def test_acquire(pool):
await pool.release(conn)
assert pool.freesize == 1
assert pool.size == 1


@pytest.mark.asyncio
async def test_clean_pool_connection_on_error(pool):
assert pool

async def raise_net_error():
raise gaierror

for _ in range(100):
async with pool.acquire() as conn:
async with conn.cursor() as cursor:
try:
# simulate network error while executing the query
await gather(
cursor.execute('SELECT 1'),
raise_net_error()
)
except gaierror:
pass

assert conn._connection.writer is None
assert conn._connection.reader is None
assert conn._connection.block_reader is None
assert conn._connection.block_reader_raw is None
assert conn._connection.block_writer is None
assert conn._connection.connected is False
assert conn._connection.client_trace_context is None
assert conn._connection.server_info is None
assert conn._connection.is_query_executing is False
Loading