elsa-workflows / elsa-core

A .NET workflows library
https://v3.elsaworkflows.io/
MIT License
6.48k stars 1.2k forks source link

Http Request run Asynchronously but the workflow got suspended and never return the result #4763

Closed jordanpedro closed 10 months ago

jordanpedro commented 10 months ago

Hi,regarding the issue https://github.com/elsa-workflows/elsa-core/issues/4737 i believe The Problem now is that the next activity after the multiple Async http calls never gets executed http-async-calls (2).json

image

and also the activity Http Request (Flow) still has the suspendend problem that i mentioned in the title of the issue.

http-flow-async-calls.json

image so , the fix via https://github.com/elsa-workflows/elsa-core/commit/7c632a5b5529df2d61b3a1e8187dd069ad09323f didnt solve the whole issue

sfmskywalker commented 10 months ago

I can confirm the issue - thanks for the great repro steps @jordanpedro ! I am woking on the fix.

sfmskywalker commented 10 months ago

The first issue is resolved via c2ec2bda5a15b34566629e87a3cd3b2c82e32fcc, very nice catch. The second issue is a different one and has to do with the fact that as soon as the engine schedules activities for execution in the background, it will create bookmarks and suspend the workflow. Once both background jobs have finished, the workflow instance is resumed from the background, at which point there is no HTTP context to write a response to, which is why the HTTP Response activity remains in the Suspended state (it's waiting for the workflow to be resumed from an HTTP context, but this never happens).

If you were to replace the HTTP Response activity with a WriteLine activity for example, then you will see that the workflow completes.

If we want to support scenarios where we execute certain activities from the background, without suspending the workflow instance, we need a different implementation where activities are executed concurrently in memory.

I think it's possible, but out of scope for this issue. Please feel free to open a separate issue requesting the parallel execution of activities while keeping the workflow instance in tact (i.e. without suspending the workflow instance).