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] FailedToConnect activity in SendHttpRequest is not executed #5591

Closed
cschulznethaus opened this issue Jun 13, 2024 · 3 comments · Fixed by #5632
Closed

[BUG] FailedToConnect activity in SendHttpRequest is not executed #5591

cschulznethaus opened this issue Jun 13, 2024 · 3 comments · Fixed by #5632
Labels
bug Something isn't working

Comments

@cschulznethaus
Copy link
Contributor

Description

I'm currently testing the behavior of SendHttpRequest, when the target is not reachable. I expected that the FailedToConnect would be executed, but nothing happens. I assigned a Fault activity to FailedToConnect which should terminate further execution, but after the failed HTTP Request the rest of the workflow is successfully executed.

Steps to Reproduce

  1. Detailed Steps:
  • Create a workflow with a SendHttpRequest activity that calls an endpoint that does not exists.
  • Assign a Fault to the FailedToConnect.
  • Trigger the workflow.
  1. Code Snippets:

Here is the example workflow I used.

public sealed class TimeoutWorkflow : WorkflowBase
{
    protected override void Build(IWorkflowBuilder builder)
    {
        var request = builder.WithVariable<TenantOffboardingRequest>().WithMemoryStorage();

        builder.Name = "Example Timeout Workflow";
        builder.Root = new Sequence
        {            
            Activities =
            {
                new HttpEndpoint
                {
                    Path = new("/timeout"),
                    SupportedMethods = new([HttpMethods.Post]),

                    CanStartWorkflow = true
                },

                new SendHttpRequest
                {
                    Url = new(new Uri($"http://localhost:1234/url-that-does-not-exist")),
                    Method = new(HttpMethods.Post),
                    UnmatchedStatusCode = new Fault(),
                    FailedToConnect = new Fault(),
                    Timeout = new Fault(),
                    ExpectedStatusCodes =
                        {
                            new HttpStatusCodeCase
                            {
                                StatusCode = StatusCodes.Status200OK
                            }
                        },
                },

                new WriteHttpResponse
                {
                    StatusCode = new(HttpStatusCode.NoContent)
                }
            }
        };
    }
}
  1. Reproduction Rate: every time

Expected Behavior

The Fault activity should terminate the workflow.

Actual Behavior

The workflow finishes successfully.

Screenshots

image

Environment

  • Elsa Package Version: 3.1.3
  • Operating System: Windows 11
  • Browser and Version: Edge 125.0.2535.92

Troubleshooting Attempts

I believe the problem lies in SendHttpRequestActivityResolver. GetPortsInternal does not yield return Timeout and FailedToConnect. I replaced SendHttpRequestActivityResolver with an adjusted version, which solved the problem for me.

    private IEnumerable<IActivity> GetPortsInternal(IActivity activity)
    {
        var sendHttpRequest = (SendHttpRequest)activity;
        var cases = sendHttpRequest.ExpectedStatusCodes.Where(x => x.Activity != null);

        foreach (var @case in cases)
            yield return @case.Activity!;

+        if (sendHttpRequest.Timeout != null)
+            yield return sendHttpRequest.Timeout;
+
+        if (sendHttpRequest.FailedToConnect != null)
+            yield return sendHttpRequest.FailedToConnect;
+
        if (sendHttpRequest.UnmatchedStatusCode != null)
            yield return sendHttpRequest.UnmatchedStatusCode;
    }
@cschulznethaus cschulznethaus added the bug Something isn't working label Jun 13, 2024
Copy link

glime-ai bot commented Jun 13, 2024

Based on the information provided, it seems that you have encountered a known issue with the SendHttpRequest activity in Elsa Workflows where the FailedToConnect and Timeout outcomes are not being properly handled. This issue has been acknowledged in the Elsa community, and a fix has been suggested which involves modifying the SendHttpRequestActivityResolver to ensure that these outcomes yield return their respective activities.

To resolve the issue, you should apply the patch you've mentioned to the SendHttpRequestActivityResolver. This will ensure that the Timeout and FailedToConnect activities are returned and can be executed when the corresponding outcomes occur.

Here's a summary of the steps you should take:

  1. Apply the patch to the SendHttpRequestActivityResolver as shown in your diff snippet.
  2. Rebuild your application with the patched version of SendHttpRequestActivityResolver.
  3. Test the workflow again to ensure that the Fault activity is now triggered when the FailedToConnect outcome occurs.

If you are not comfortable applying the patch yourself or if you encounter any issues, you may want to reach out to the Elsa Workflows community for further assistance or to check if there is an updated version of Elsa that includes the fix for this issue.

Please note that modifying the source code of a library can lead to maintenance challenges, so it's always best to check for official fixes or updates before applying custom patches.

This comment was generated by Glime.

@jdevillard
Copy link
Contributor

Hello,

Thanks for this issue, I think you're right, would you like to create a PR to submit your change ?

@cschulznethaus
Copy link
Contributor Author

Took me some time to get around to this, but I finally created the PR.

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

Successfully merging a pull request may close this issue.

2 participants