[BugFix] Fix async core engine client finalizer (#24540)

Signed-off-by: Nick Hill <nhill@redhat.com>
This commit is contained in:
Nick Hill 2025-09-09 21:07:13 -07:00 committed by GitHub
parent 3c2156b3af
commit f88e84016f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -347,8 +347,9 @@ class BackgroundResources:
if isinstance(self.output_socket, zmq.asyncio.Socket):
# Async case.
loop = self.output_socket._get_loop()
asyncio.get_running_loop()
loop = self.output_queue_task._loop \
if self.output_queue_task else None
sockets = (self.output_socket, self.input_socket,
self.first_req_send_socket, self.first_req_rcv_socket,
self.stats_update_socket)
@ -359,11 +360,12 @@ class BackgroundResources:
close_sockets(sockets)
for task in tasks:
if task is not None and not task.done():
task.cancel()
with contextlib.suppress(Exception):
task.cancel()
if in_loop(loop):
close_sockets_and_tasks()
elif not loop.is_closed():
elif loop and not loop.is_closed():
loop.call_soon_threadsafe(close_sockets_and_tasks)
else:
# Loop has been closed, try to clean up directly.