Azure / azure-functions-durable-js

JavaScript library for using the Durable Functions bindings
https://www.npmjs.com/package/durable-functions
MIT License
128 stars 46 forks source link

waitForExternalEvent not completing in reasonable time when event arrives early #558

Open Neutroni opened 8 months ago

Neutroni commented 8 months ago

Describe the bug context.df.waitForExternalEvent() in context.df.Task.any() does not complete quickly in case the event arrives too early or in some cases seemingly at all. We have a system where durable orchestrator calls activity function which calls external service which starts some processes one of which will send the event trough httpTrigger but in case the external server and the activity function return later than the started process triggers the event we are seeing long waits for waitForExternalEvent in the orchestrator. With durable-functions npm module version 1.5.4 same code completes instantly but with versions 2 and later the event does not trigger correctly.

Investigative information

To Reproduce Have orchestrator which waits for event and calls activity function where the activity function triggers the event, see sample code for example.

Orchestrator source code (minimal example): index.ts

Activity function source code (minimal example): index.ts

In the sample code the context.df.Task.any() seemingly completes when timeout task completes but the waitForExternalEvent task wins since it received event long before. Modify duration of deadline task to see it changing when waitForExternalEvent completes, or remove the deadline task from the Task.any and code seemingly never completes

Expected behavior context.df.waitForExternalEvent() in context.df.Task.any() completes quickly when waitForExternalEvent has received the event.

Actual behavior context.df.waitForExternalEvent() in context.df.Task.any() completes when other task in Task.any() completes or in case there is not other task seemingly never.

Additional context