Skip to content
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
* Fix repeated `ydb.aio.Driver.stop()` raising `CancelledError` after discovery was cancelled during shutdown.

## 3.38.0 ##
* Add automatic long polling for endpoint discovery in sync and asyncio drivers
* Add `EventHandler.on_partition_session_start` to confirm topic reader partitions manually with read and commit offsets, and `EventHandler.on_partition_session_stop` to observe partition stops.
Expand Down
20 changes: 20 additions & 0 deletions tests/aio/test_connection_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,26 @@
import ydb


@pytest.mark.asyncio
async def test_repeated_stop_during_discovery(monkeypatch):
connecting = asyncio.Event()
connection_ready = asyncio.get_running_loop().create_future()

async def wait_for_connection(self, ready_timeout=10):
connecting.set()
await connection_ready

monkeypatch.setattr("ydb.aio.connection.Connection.connection_ready", wait_for_connection)
driver = Driver(endpoint="localhost:2135", database="/local")
try:
await asyncio.wait_for(connecting.wait(), timeout=5)
finally:
await asyncio.gather(driver.stop(timeout=0), driver.stop())

assert connection_ready.cancelled()
await driver.stop(timeout=0)


@pytest.mark.asyncio
async def test_async_call(endpoint, database):
driver_config = ydb.DriverConfig(
Expand Down
11 changes: 8 additions & 3 deletions ydb/aio/driver.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import asyncio
from typing import Any, Optional, TYPE_CHECKING

from . import pool, scheme, table
Expand Down Expand Up @@ -74,6 +75,7 @@ def __init__(

super(Driver, self).__init__(config)

self._stop_lock = asyncio.Lock()
self._credentials = config.credentials

self.scheme_client = scheme.SchemeClient(self)
Expand All @@ -82,6 +84,9 @@ def __init__(
self.coordination_client = coordination.CoordinationClient(self)

async def stop(self, timeout: int = 10) -> None: # type: ignore[override] # async override of sync method
await self.table_client._stop_pool_if_needed(timeout=timeout)
self.topic_client.close()
await super().stop(timeout=timeout)
async with self._stop_lock:
if self._stopped:
return
await self.table_client._stop_pool_if_needed(timeout=timeout)
self.topic_client.close()
await super().stop(timeout=timeout)
Loading