Skip to content

Commit 0b6e9c7

Browse files
committed
Only gather tasks that we actually spawn
1 parent 62ac8a7 commit 0b6e9c7

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

juju/client/connection.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,11 +442,15 @@ async def close(self, to_reconnect=False):
442442
self.monitor.close_called.set()
443443

444444
# Cancel all the tasks (that we started):
445+
tasks_need_to_be_gathered = []
445446
if self._pinger_task:
447+
tasks_need_to_be_gathered.append(self._pinger_task)
446448
self._pinger_task.cancel()
447449
if self._receiver_task:
450+
tasks_need_to_be_gathered.append(self._receiver_task)
448451
self._receiver_task.cancel()
449452
if self._debug_log_task:
453+
tasks_need_to_be_gathered.append(self._debug_log_task)
450454
self._debug_log_task.cancel()
451455

452456
if self._ws and not self._ws.closed:
@@ -456,7 +460,6 @@ async def close(self, to_reconnect=False):
456460
if not to_reconnect:
457461
try:
458462
log.debug('Gathering all tasks for connection close')
459-
tasks_need_to_be_gathered = [self._receiver_task, self._pinger_task]
460463
await jasyncio.gather(*tasks_need_to_be_gathered)
461464
except jasyncio.CancelledError:
462465
pass

0 commit comments

Comments
 (0)