microsoft / microsoft/durabletask-dotnet
Listening for same event recurringly does not resolve latest non-canceled task
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 193
- Forks
- 60
- Avg merge
- 3d 12h
- Merged PRs (30d)
- 4
Description
The docs of TaskOrchestrationContext.WaitForExternalEvent state:
Orchestrators can wait for the same event name multiple times, so waiting for multiple events with the same name is allowed. Each external event received by an orchestrator will complete just one task returned by this method.
However, when cancelling an earlier listener task before any event with that name has arrived, a later listener task won't be resolved by the next arriving event.
I've created a minimal reproduction in this repository, specifically inside MyOrchestration.cs where a listener for event name "RecurringEvent" is registered three times while only one listener is active (meaning not-cancelled) at a time and only the last listener is meant to resolve.
After starting the orchestrator via http://localhost:7071/api/MyOrchestration_HttpStart, I'd expect the following steps to result in its completion:
- Raise event "OneTimeEvent1"
- Raise event "OneTimeEvent2"
- Raise event "RecurringEvent"
Instead, the orchestrator only completes after sending "RecurringEvent" one more time:
- Raise event "OneTimeEvent1"
- Raise event "OneTimeEvent2"
- Raise event "RecurringEvent"
- Raise event "RecurringEvent"
At first I thought the runtime might serve earlier listeners even though they're canceled, however, this does not seem to be exactly the case since I'm registering three listeners while its sufficient to send the corresponding event only two times.
System Info
- MacBook Pro M1 Ventura 13.2.1 / Windows 10 on Desktop PC
- Azurite for Storage Emulation
Workaround
I've refactored code that relied on this pattern to hold a reference to a single listener instead of cancelling earlier listeners and starting new ones.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked MyOrchestration.cs reproduction and the TaskOrchestrationContext.WaitForExternalEvent entry point. Reproduce the cancellation sequence using the documented HTTP start and event steps, then trace how canceled and recurring listeners are matched. Done means one RecurringEvent resolves the latest non-canceled listener after the earlier listeners are canceled.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100