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] Problem with WriteHttpResponse Activity on External Workflow Start #5270

Open
je-git-32 opened this issue Apr 24, 2024 · 3 comments
Open
Labels
bug Something isn't working

Comments

@je-git-32
Copy link

Description

In my scenario, there are two workflows, A and B. A has a cron job that starts B every x minutes. B has no interruptions and is supposed to run continuously every x minutes. Now, my problem is that when the workflow is triggered by A, the WriteHttpResponse activity does not terminate but goes into a suspended state. If I manually start B, this problem does not occur, so I suspect an issue in the interaction between the cron job and the WriteHttpResponse activity.

Steps to Reproduce

The problem can be simplified from two workflows to one. If we create a workflow C that is supposed to be started by a cron job every x minutes and it contains a WriteHttpResponse somewhere, it gets stuck at the WriteHttpResponse, and the workflow remains in a suspended state without progressing. Also, it's worth mentioning that if we don't use a cron activity to start the workflow, i.e., if we execute it manually, the problem does not occur.

What I have tested so far:

Manually starting the workflow: works
Starting the workflow via cron: suspended
Starting the workflow via event: suspended

Attachments

Workflow without cron/ event:
Screenshot 2024-04-24 072339

Execution:
Screenshot 2024-04-24 072358

Workflow with cron:
Screenshot 2024-04-24 072316

Execution:
Screenshot 2024-04-24 072417

Workflow with event:
Screenshot 2024-04-24 072455

Execution:
Screenshot 2024-04-24 072530

Expected Behavior

I expect the workflow to finish, just as it does without the cron/event.

Actual Behavior

The workflow gets into a suspended state and does not continue.

Related Issues

Issues that I found also have a problem with the WriteHttpResponse:

The issue I mentioned earlier:

@je-git-32 je-git-32 added the bug Something isn't working label Apr 24, 2024
Copy link

glime-ai bot commented Apr 24, 2024

Based on the information provided and the related issues from the Elsa GitHub repository, it seems that the problem you are experiencing with the WriteHttpResponse activity entering a suspended state when triggered by a cron job is related to the HTTP context not being available when the workflow is resumed from a background job.

In the context of HTTP workflows, the WriteHttpResponse activity expects an HTTP context to be present so it can write the response back to the client. However, when a workflow is triggered by a cron job or an event that does not originate from an HTTP request, there is no HTTP context available. This is why the activity goes into a suspended state, as it's waiting for an HTTP context to become available, which never happens in the case of cron-triggered workflows.

To resolve this issue, you would need to ensure that the WriteHttpResponse activity is only used in workflows that are triggered by HTTP requests, or you would need to modify the workflow design to not rely on HTTP context when triggered by cron jobs or events.

For workflows that need to perform actions in the background and then respond to an HTTP request, you might consider splitting the workflow into two parts: one that handles the background processing and another that handles the HTTP response. This way, the HTTP response part of the workflow is only executed in the context of an HTTP request.

If you need further assistance with this issue, you may want to reach out to the Elsa community or maintainers for more specific guidance or to check if there have been any updates or workarounds since the last known issues.

This comment was generated by Glime.

@je-git-32
Copy link
Author

Hey, thanks, Glime-AI. But in my case, the workflow is triggered and not resumed. So, a new instance is started, and therefore, a new HttpContext should exist.

@jdevillard
Copy link
Contributor

Hello,

When you manually start the Workflow, it's using an Http API and so you will have an HttpContext.
But when you start your workflow from trigger or event, you will not have any HttpContext because the Workflow is started/resume from background service.

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