Skip to content

Commit 550a006

Browse files
committed
Merge branch 'master' into asyncio-module-integration-tests2
# Conflicts: # hazelcast/internal/asyncio_connection.py # hazelcast/internal/asyncio_reactor.py
2 parents 6da4226 + c72eafa commit 550a006

File tree

3 files changed

+19
-15
lines changed

3 files changed

+19
-15
lines changed

hazelcast/internal/asyncio_connection.py

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ def __init__(
187187
)
188188
# asyncio tasks are weakly referenced
189189
# storing tasks here in order not to lose them midway
190+
# see: https: // docs.python.org / 3 / library / asyncio - task.html # creating-tasks
190191
self._tasks = set()
191192

192193
def add_listener(self, on_connection_opened=None, on_connection_closed=None):
@@ -318,21 +319,22 @@ async def on_connection_close(self, closed_connection):
318319
disconnected = False
319320
removed = False
320321
trigger_reconnection = False
321-
connection = self.active_connections.get(remote_uuid, None)
322-
if connection == closed_connection:
323-
self.active_connections.pop(remote_uuid, None)
324-
removed = True
325-
_logger.info(
326-
"Removed connection to %s:%s, connection: %s",
327-
remote_address,
328-
remote_uuid,
329-
connection,
330-
)
322+
async with self._lock:
323+
connection = self.active_connections.get(remote_uuid, None)
324+
if connection == closed_connection:
325+
self.active_connections.pop(remote_uuid, None)
326+
removed = True
327+
_logger.info(
328+
"Removed connection to %s:%s, connection: %s",
329+
remote_address,
330+
remote_uuid,
331+
connection,
332+
)
331333

332-
if not self.active_connections:
333-
trigger_reconnection = True
334-
if self._client_state == ClientState.INITIALIZED_ON_CLUSTER:
335-
disconnected = True
334+
if not self.active_connections:
335+
trigger_reconnection = True
336+
if self._client_state == ClientState.INITIALIZED_ON_CLUSTER:
337+
disconnected = True
336338

337339
if disconnected:
338340
self._lifecycle_service.fire_lifecycle_event(LifecycleState.DISCONNECTED)
@@ -813,6 +815,7 @@ def __init__(self, connection_manager, client, config, reactor, invocation_servi
813815
self._heartbeat_task: asyncio.Task | None = None
814816
# asyncio tasks are weakly referenced
815817
# storing tasks here in order not to lose them midway
818+
# see: https: // docs.python.org / 3 / library / asyncio - task.html # creating-tasks
816819
self._tasks = set()
817820

818821
def start(self):

hazelcast/internal/asyncio_reactor.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ def __init__(self, conn: AsyncioConnection):
175175
self._alive = True
176176
# asyncio tasks are weakly referenced
177177
# storing tasks here in order not to lose them midway
178+
# see: https: // docs.python.org / 3 / library / asyncio - task.html # creating-tasks
178179
self._tasks: set = set()
179180

180181
def connection_made(self, transport: transports.BaseTransport):

tests/integration/asyncio/proxy/map_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@ async def test_add_entry_listener_item_loaded(self):
629629
collector = event_collector()
630630
await self.map.add_entry_listener(include_value=True, loaded_func=collector)
631631
await self.map.put("key", "value", ttl=0.1)
632-
time.sleep(2)
632+
await asyncio.sleep(2)
633633
await self.map.get("key")
634634

635635
def assert_event():

0 commit comments

Comments
 (0)