Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Prevent a deadlock on provider error in py automation api #11595

Merged
merged 2 commits into from Dec 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -0,0 +1,4 @@
changes:
- type: fix
scope: sdk/python
description: Fix a deadlock on provider-side error with automation api
10 changes: 10 additions & 0 deletions sdk/python/lib/pulumi/automation/_server.py
Expand Up @@ -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()

Expand All @@ -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:
Expand Down