Fix task cancellation issues

This fixes an issue where HTTP requests invoking workflows are aborted mid-way when e.g. WriteHttpResponse executes, causing the pipleine to trigger the RequestAborted cancelation token (which is used throughout the request into other services).
This commit is contained in:
Sipke Schoorstra 2021-05-17 13:11:55 +02:00
parent 8e325881a4
commit c87e282bc2
2 changed files with 8 additions and 4 deletions

View file

@ -8,6 +8,7 @@ using Elsa.Expressions;
using Elsa.Services;
using Elsa.Services.Models;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Features;
using Microsoft.Extensions.Localization;
// ReSharper disable once CheckNamespace
@ -38,9 +39,10 @@ namespace Elsa.Activities.Http
UIHint = ActivityPropertyUIHints.Dropdown,
Hint = "The HTTP status code to write.",
Options = new[] { HttpStatusCode.OK, HttpStatusCode.Created, HttpStatusCode.Accepted, HttpStatusCode.NoContent, HttpStatusCode.Redirect, HttpStatusCode.BadRequest, HttpStatusCode.NotFound, HttpStatusCode.Conflict },
SupportedSyntaxes = new[] { SyntaxNames.Literal, SyntaxNames.JavaScript, SyntaxNames.Liquid }
SupportedSyntaxes = new[] { SyntaxNames.Literal, SyntaxNames.JavaScript, SyntaxNames.Liquid },
DefaultValue = HttpStatusCode.OK
)]
public HttpStatusCode StatusCode { get; set; }
public HttpStatusCode StatusCode { get; set; } = HttpStatusCode.OK;
/// <summary>
/// The content to send along with the response
@ -55,9 +57,10 @@ namespace Elsa.Activities.Http
UIHint = ActivityPropertyUIHints.Dropdown,
Hint = "The HTTP content type header to write.",
Options = new[] { "text/plain", "text/html", "application/json", "application/xml" },
DefaultValue = "text/plain",
SupportedSyntaxes = new[] { SyntaxNames.Literal, SyntaxNames.JavaScript, SyntaxNames.Liquid }
)]
public string? ContentType { get; set; }
public string? ContentType { get; set; } = "text/plain";
/// <summary>
/// The headers to send along with the response.

View file

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Elsa.Activities.Http.Bookmarks;
using Elsa.Activities.Http.Extensions;
@ -31,9 +32,9 @@ namespace Elsa.Activities.Http.Middleware
IWorkflowBlueprintReflector workflowBlueprintReflector,
IEnumerable<IHttpRequestBodyParser> contentParsers)
{
var cancellationToken = CancellationToken.None; // Prevent half-way request abortion (which also happens when WriteHttpResponse writes to the response).
var path = httpContext.Request.Path.Value.ToLowerInvariant();
var method = httpContext.Request.Method!.ToLowerInvariant();
var cancellationToken = httpContext.RequestAborted;
var request = httpContext.Request;
request.TryGetCorrelationId(out var correlationId);
var useDispatch = httpContext.Request.GetUseDispatch();