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

[Bug] workflow.wait broken with asyncio.FIRST_COMPLETED and local activities #699

Open
andmis opened this issue Dec 9, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@andmis
Copy link

andmis commented Dec 9, 2024

What are you really trying to do?

Start N local activities, wait for the first one to finish, cancel the others.

Describe the bug

If I start N local activities, then use workflow.wait(tasks, return_when=asyncio.FIRST_COMPLETED), the workflow.wait coro blocks until all of the activities actually finish, instead of returning when the first one finishes. If I use non-local activities, this bug does not happen.

Minimal Reproduction

https://github.com/andmis/snippets/tree/temporal-python-sdk-local-activity-workflow-wait-bug

# Worker output after `python run_workflow.py`
2024-12-09 19:02:30.750775+00:00 (Workflow) Starting, local=False
2024-12-09 19:02:30.750775+00:00 (Workflow) Waiting for first completed activity
2024-12-09 11:02:30.760073 (Activity 0) Running sandbox_activity
2024-12-09 11:02:30.760565 (Activity 1) Running sandbox_activity
2024-12-09 11:02:32.875597 (Activity 1) Exiting sandbox_activity
2024-12-09 19:02:32.891753+00:00 (Workflow) Got first completed activity, cancelling others and exiting
2024-12-09 19:02:32.891753+00:00 (Workflow) Exiting
2024-12-09 11:02:35.328912 (Activity 0) Cancelling sandbox_activity

# Worker output after `python run_workflow.py -l`
2024-12-09 19:03:48.421271+00:00 (Workflow) Starting, local=True
2024-12-09 19:03:48.421271+00:00 (Workflow) Waiting for first completed activity
2024-12-09 11:03:48.425911 (Activity 0) Running sandbox_activity
2024-12-09 11:03:48.426165 (Activity 1) Running sandbox_activity
2024-12-09 11:03:49.817020 (Activity 1) Exiting sandbox_activity
2024-12-09 11:03:56.397142 (Activity 0) Exiting sandbox_activity
2024-12-09 19:03:56.394210+00:00 (Workflow) Got first completed activity, cancelling others and exiting
2024-12-09 19:03:56.394210+00:00 (Workflow) Exiting
# Note the timestamps

Environment/Versions

  • OS and processor: macOS, M1
  • Temporal version: 1.1.2
  • Python SDK version: 1.8.0
  • Are you using Docker or Kubernetes or building Temporal from source? No

Additional context

@andmis andmis added the bug Something isn't working label Dec 9, 2024
@andmis andmis changed the title [Bug] FILL_TITLE_HERE [Bug] workflow.wait broken with asyncio.FIRST_COMPLETED and local activities Dec 9, 2024
@cretz
Copy link
Member

cretz commented Dec 9, 2024

Thanks! We will investigate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants