From a23f3ac9df4e918f3fab138a35a6316ce7b47cfe Mon Sep 17 00:00:00 2001 From: Julien 'Lta' BALLET Date: Thu, 8 Dec 2022 17:28:35 +0100 Subject: [PATCH 1/2] fix: Prevent a deadlock on provider error in py automation api --- sdk/python/lib/pulumi/automation/_server.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/sdk/python/lib/pulumi/automation/_server.py b/sdk/python/lib/pulumi/automation/_server.py index 13c2f6ce8651..ccdd8cd56f6a 100644 --- a/sdk/python/lib/pulumi/automation/_server.py +++ b/sdk/python/lib/pulumi/automation/_server.py @@ -43,6 +43,15 @@ def on_pulumi_exit(): def GetRequiredPlugins(self, request, context): return language_pb2.GetRequiredPluginsResponse() + def _exception_handler(self, loop, context): + # Exception are normally handler deeper in the stack. If this class of + # exception bubble up to here, something is wrong and we should stop + # the event loop + if "exception" in context and isinstance(context["exception"], grpc.RpcError): + loop.stop() + else: + loop.default_exception_handler(context) + def Run(self, request, context): _suppress_unobserved_task_logging() @@ -67,6 +76,7 @@ def Run(self, request, context): result = language_pb2.RunResponse() loop = asyncio.new_event_loop() + loop.set_exception_handler(self._exception_handler) try: loop.run_until_complete(run_in_stack(self.program)) except RunError as exn: From 4e16d53c14576949b3d951750ab1b650f914b972 Mon Sep 17 00:00:00 2001 From: Julien 'Lta' BALLET Date: Thu, 8 Dec 2022 17:37:44 +0100 Subject: [PATCH 2/2] docs: Add changelog entry --- ...a-deadlock-on-provider-side-error-with-automation-api.yaml | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 changelog/pending/20221208--sdk-python--fix-a-deadlock-on-provider-side-error-with-automation-api.yaml diff --git a/changelog/pending/20221208--sdk-python--fix-a-deadlock-on-provider-side-error-with-automation-api.yaml b/changelog/pending/20221208--sdk-python--fix-a-deadlock-on-provider-side-error-with-automation-api.yaml new file mode 100644 index 000000000000..94f14ac1dd86 --- /dev/null +++ b/changelog/pending/20221208--sdk-python--fix-a-deadlock-on-provider-side-error-with-automation-api.yaml @@ -0,0 +1,4 @@ +changes: +- type: fix + scope: sdk/python + description: Fix a deadlock on provider-side error with automation api