elsa-workflows / elsa-core

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

[BUG] Http Response activity doesnt send the response before completing. #5267

Open ciaranodonnell opened 3 weeks ago

ciaranodonnell commented 3 weeks ago

Description

The WriteHttpResponse activity doesn't flush the response in the HttpContext and therefore it seems common that the response isn't really sent until the workflow ends.

Steps to Reproduce

Create a workflow with an Http Endpoint trigger. Add an Http Response activity next that just has an Accepted status. Then add more activities after that to do work, or even just Delay the workflow. When the workflow runs the response is not written back to the Http caller before the Http Response activity completed.

  1. Detailed Steps: Provide a step-by-step description of what leads to the bug. Be as specific as possible. As Above

  2. Reproduction Rate: Indicate how often the bug occurs when following these steps (e.g., "every time", "intermittently: about 50% of the time"). For us, Every time

Expected Behavior

Describe what you expected to happen.

When the activity completes it should call CompelteAsync() on the response so its flushed to the client This should happen here: https://github.com/elsa-workflows/elsa-core/blob/main/src/modules/Elsa.Http/Activities/WriteHttpResponse.cs#L137

Actual Behavior

Describe what actually happened. Include screenshots, if applicable.

It doesn't call that so the response isn't written for sure.

Environment

This is still the case on the main branch: https://github.com/elsa-workflows/elsa-core/blob/main/src/modules/Elsa.Http/Activities/WriteHttpResponse.cs#L137

glime-ai[bot] commented 3 weeks ago

Based on the context provided, it appears that you are experiencing an issue where the WriteHttpResponse activity in an Elsa Workflow does not immediately flush the response to the HTTP caller, but instead waits until the entire workflow has completed. This behavior is not what you expected, as you would like the HTTP response to be sent as soon as the WriteHttpResponse activity completes, even if there are subsequent activities in the workflow, such as a delay.

This issue has been recognized in the Elsa community, as seen in the GitHub issue discussions. The expected behavior would be for the WriteHttpResponse activity to call CompleteAsync() on the response object to ensure it is flushed to the client immediately after the activity executes.

As of the information provided, this behavior is still present in the main branch of the Elsa GitHub repository. A potential solution would be to modify the WriteHttpResponse activity to include a call to CompleteAsync() or a similar method that would flush the response immediately.

For a more detailed discussion or potential fixes, you may want to follow up on the GitHub issues and discussions related to this topic, or reach out to the maintainers of the Elsa project for assistance.

This comment was generated by Glime.

jdevillard commented 3 weeks ago

link to #4701