question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

I’m running the AspnetCore Monolith Dashboard sample.

Workflow:,

image

This problem happens in the HttpReponse Activity, the HttpEndpoint works fine

I’m getting an error on the client which I can’t catch in the server, I think the problem happens in:

Elsa.Activities.Http -> WriteHttpResponse -> OnExecuteAsync(ActivityExecutionContext context)

It seems that response.WriteAsync fires some background thread that fails at some point but the exception is not caught:

        /// <summary>
        /// The headers to send along with the response.
        /// </summary>
        [ActivityProperty(Hint = "Additional headers to write.", UIHint = ActivityPropertyUIHints.Json)]
        public HttpResponseHeaders? ResponseHeaders { get; set; }

        protected override async ValueTask<IActivityExecutionResult> OnExecuteAsync(ActivityExecutionContext context)
        {
    
            var httpContext = _httpContextAccessor.HttpContext ?? new DefaultHttpContext();
            var response = httpContext.Response;

          ...

            var bodyText = Content;

            if (!string.IsNullOrWhiteSpace(bodyText))
            {
                try
                {
                    
                    await response.WriteAsync(bodyText, context.CancellationToken); 
                  
                    await Task.Delay(5000);      <--CLIENT FAILS HERE
                    Console.WriteLine("Delay End");
                  
                   
                }
                catch(Exception ex)
                {
                    var z = ex;
                }
            }
           
            return Done();
        }

The API function has not returned when the client already fails:

image

image

Client only says “Unknown Backend Error, Status = 0”

The workflow instances are created and Finished OK

image

This doesn’t happen if the call is made from the browser, so it has to be CORS related

I’m using Angular 10, tried in a clean empty project, no credentials, no extra headers in the http call

(English is not my primary language, sorry for the errors)

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
atorres16commented, May 26, 2021

I think it was the order of the Http request pipeline config, I moved app.UseCors() to the top and it worked

Startup.cs

  public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
        ...
            app.UseCors(); //YES
            app.UseStaticFiles();
            app.UseHttpActivities();
            //app.UseCors(); //NO
            app.UseRouting();
            app.UseAuthorization();
          ...
        }
0reactions
atorres16commented, May 26, 2021

Sorry, I closed this issue by mistake

Read more comments on GitHub >

github_iconTop Results From Across the Web

CORS errors - HTTP - MDN Web Docs - Mozilla
If the CORS configuration isn't setup correctly, the browser console will present an error like "Cross-Origin Request Blocked: The Same ...
Read more >
Understanding and Resolving CORS Error
The CORS behavior, commonly termed as CORS error, is a mechanism to restrict users from accessing shared resources. This is not an error...
Read more >
3 Ways to Fix the CORS Error — and How the Access- ...
The error stems from a security mechanism that browsers implement called the same-origin policy. The same-origin policy fights one of the most ...
Read more >
What Is a CORS Error and How to Fix It (3 Ways)
As a CORS error occurs when the external API server doesn't return the HTTP headers required by the CORS standard, you can add...
Read more >
CORS Errors: Cross-Origin Resource Sharing
CORS errors happen in web apps if requests are made and servers don't return required headers. Read about Cross-Origin Resource Sharing in Ionic ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found