You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using the Default HttpRequestMessage activity, if the response contains a body but no content-type the first parser that attempts to read the content-type will throw a NullReferenceException.
Steps to Reproduce
To help us identify the issue more quickly, please follow these guidelines:
Detailed Steps: I used the following workflow in the sample web server (src/apps/Elsa.Server.Web/) to test my solution.
You just need to invoke it to observe bug.
using System.Net;
using System.Net.Mime;
using Elsa.Http;
using Elsa.Workflows;
using Elsa.Workflows.Activities;
using Elsa.Workflows.Contracts;
namespace Elsa.Server.Web.Activities;
public class WeatherForecastWorkflow : WorkflowBase
{
protected override void Build(IWorkflowBuilder builder)
{
var uri =
builder.Root = new Sequence
{
Activities =
{
new HttpEndpoint
{
Path = new("/poc"),
SupportedMethods = new(new[] { HttpMethods.Get }),
CanStartWorkflow = true
},
new SendHttpRequest
{
//I'll provide a sample project later
Url = new(new Uri("http://localhost:5100")),
Method = new(HttpMethods.Put)
},
// Write back the weather forecast.
new WriteHttpResponse
{
ContentType = new(MediaTypeNames.Text.Html),
StatusCode = new(HttpStatusCode.OK),
Content = new(context =>
{
return "Hello";
})
}
}
};
}
}
Code Snippets: no other relevant snippet.
Attachments:
Sample Project: You can reproduce the error with the following simple c# server
using System.Net;
using System.Net.Sockets;
using System.Text;
var response = Encoding.UTF8.GetBytes(@"HTTP/1.1 403
Date: Sat, 24 Aug 2024 13:02:23 GMT
Content-Length: 43
Connection: keep-alive
Server: openresty
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: POST, GET, PUT, DELETE, OPTIONS,HEAD
Access-Control-Allow-Headers: Content-Type, gumgaToken, Connection, userRecognition
{""response"":""some_info"",""operation"":""general""}");
var lookback = IPAddress.Parse("127.0.0.1");
var ipAddress = new IPEndPoint(lookback,5100);
var listener = new TcpListener(ipAddress);
Console.WriteLine($"Listening at: {ipAddress} ");
try
{
listener.Start();
while(true)
{
using var handler = listener.AcceptTcpClient();
using var stream = handler.GetStream();
stream.Write(response);
}
}
finally
{
listener.Stop();
}
Reproduction Rate: every time
Video/Screenshots: I don't believe it's necessary, but, I can provide one if needed
Additional Configuration: I don't believe it's necessary.
Expected Behavior
The workflow should continue without a exception.
Actual Behavior
The api returns a 500 exception and the workflow is suspended.
Screenshots
If possible, add screenshots or screen recordings to help explain the problem.
Environment
Elsa Package Version: Elsa 3.1.3 and latest commit from main.
Operating System: Fedora 40 (6.10.4)
Browser and Version: Not applicable
Log Output
System.NullReferenceException Object reference not set to an instance of an object.
at Elsa.Extensions.HttpActivityExecutionContextExtensions.<>c__DisplayClass0_0.b__1(IHttpContentParser x)
at System.Linq.Enumerable.TryGetFirst[TSource](IEnumerable1 source, Func2 predicate, Boolean& found)
at Elsa.Extensions.HttpActivityExecutionContextExtensions.ParseContentAsync(ActivityExecutionContext context, Stream content, String contentType, Type returnType, CancellationToken cancellationToken)
at Elsa.Http.SendHttpRequestBase.ParseContentAsync(ActivityExecutionContext context, HttpContent httpContent)
at Elsa.Http.SendHttpRequestBase.TrySendAsync(ActivityExecutionContext context)
at Elsa.Http.SendHttpRequestBase.ExecuteAsync(ActivityExecutionContext context)
at Elsa.Workflows.Activity.Elsa.Workflows.Contracts.IActivity.ExecuteAsync(ActivityExecutionContext context)
at Elsa.Workflows.Middleware.Activities.DefaultActivityInvokerMiddleware.ExecuteActivityAsync(ActivityExecutionContext context)
at Elsa.Workflows.Runtime.Middleware.Activities.BackgroundActivityInvokerMiddleware.ExecuteActivityAsync(ActivityExecutionContext context)
at Elsa.Workflows.Middleware.Activities.DefaultActivityInvokerMiddleware.InvokeAsync(ActivityExecutionContext context)
at Elsa.Workflows.Middleware.Activities.NotificationPublishingMiddleware.InvokeAsync(ActivityExecutionContext context)
at Elsa.Workflows.Middleware.Activities.ExecutionLogMiddleware.InvokeAsync(ActivityExecutionContext context)
Troubleshooting Attempts
I could not create a workaround using the workflow studio, but, I could fix it changing the SendHttpRequestBase class, in the ParseContentAsync method, instead of using the null-forgiving operator when creating the contentType variable adding a default value of application/octet-stream
After this change it was necessary to modify the FileHttpContentParser to use the TryGetValue method instead of accessing the Header dictionary directly.
Additional Context
Add any other context about the problem here. This could include the frequency of the issue (e.g., intermittent, every time), conditions under which the issue appears, etc.
Related Issues
Link to any related issues here.
The text was updated successfully, but these errors were encountered:
Description
When using the Default HttpRequestMessage activity, if the response contains a body but no content-type the first parser that attempts to read the content-type will throw a NullReferenceException.
Steps to Reproduce
To help us identify the issue more quickly, please follow these guidelines:
You just need to invoke it to observe bug.
Code Snippets: no other relevant snippet.
Attachments:
Reproduction Rate: every time
Video/Screenshots: I don't believe it's necessary, but, I can provide one if needed
Additional Configuration: I don't believe it's necessary.
Expected Behavior
The workflow should continue without a exception.
Actual Behavior
The api returns a 500 exception and the workflow is suspended.
Screenshots
If possible, add screenshots or screen recordings to help explain the problem.
Environment
Log Output
System.NullReferenceException Object reference not set to an instance of an object.
at Elsa.Extensions.HttpActivityExecutionContextExtensions.<>c__DisplayClass0_0.b__1(IHttpContentParser x)
at System.Linq.Enumerable.TryGetFirst[TSource](IEnumerable
1 source, Func
2 predicate, Boolean& found)at Elsa.Extensions.HttpActivityExecutionContextExtensions.ParseContentAsync(ActivityExecutionContext context, Stream content, String contentType, Type returnType, CancellationToken cancellationToken)
at Elsa.Http.SendHttpRequestBase.ParseContentAsync(ActivityExecutionContext context, HttpContent httpContent)
at Elsa.Http.SendHttpRequestBase.TrySendAsync(ActivityExecutionContext context)
at Elsa.Http.SendHttpRequestBase.ExecuteAsync(ActivityExecutionContext context)
at Elsa.Workflows.Activity.Elsa.Workflows.Contracts.IActivity.ExecuteAsync(ActivityExecutionContext context)
at Elsa.Workflows.Middleware.Activities.DefaultActivityInvokerMiddleware.ExecuteActivityAsync(ActivityExecutionContext context)
at Elsa.Workflows.Runtime.Middleware.Activities.BackgroundActivityInvokerMiddleware.ExecuteActivityAsync(ActivityExecutionContext context)
at Elsa.Workflows.Middleware.Activities.DefaultActivityInvokerMiddleware.InvokeAsync(ActivityExecutionContext context)
at Elsa.Workflows.Middleware.Activities.NotificationPublishingMiddleware.InvokeAsync(ActivityExecutionContext context)
at Elsa.Workflows.Middleware.Activities.ExecutionLogMiddleware.InvokeAsync(ActivityExecutionContext context)
Troubleshooting Attempts
I could not create a workaround using the workflow studio, but, I could fix it changing the SendHttpRequestBase class, in the ParseContentAsync method, instead of using the null-forgiving operator when creating the contentType variable adding a default value of application/octet-stream
After this change it was necessary to modify the FileHttpContentParser to use the TryGetValue method instead of accessing the Header dictionary directly.
Additional Context
Add any other context about the problem here. This could include the frequency of the issue (e.g., intermittent, every time), conditions under which the issue appears, etc.
Related Issues
Link to any related issues here.
The text was updated successfully, but these errors were encountered: