[BugFix] Handle case where async utility call is cancelled (#22996)

Signed-off-by: Nick Hill <nhill@redhat.com>
Co-authored-by: Yinghai Lu <yinghai@thinkingmachines.ai>
This commit is contained in:
Nick Hill
2025-08-15 16:38:42 -07:00
committed by GitHub
parent 1fc375dc05
commit b9dc9d2607
2 changed files with 38 additions and 7 deletions

View File

@@ -574,13 +574,22 @@ class MPClient(EngineCoreClient):
def _process_utility_output(output: UtilityOutput,
utility_results: dict[int, AnyFuture]):
"""Set the result from a utility method in the waiting future"""
"""Set the result from a utility method in the waiting future."""
future = utility_results.pop(output.call_id)
if output.failure_message is not None:
future.set_exception(Exception(output.failure_message))
else:
assert output.result is not None
future.set_result(output.result.result)
failure_message = output.failure_message
try:
if failure_message is not None:
future.set_exception(Exception(failure_message))
else:
assert output.result is not None
future.set_result(output.result.result)
except asyncio.InvalidStateError:
# This can happen if the future is cancelled due to the
# original calling task being cancelled.
if failure_message is not None:
logger.error(
"Cancelled call to utility method failed "
"with error: %s", failure_message)
class SyncMPClient(MPClient):