[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:
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user