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

Can't send Http request in IEventHandler #187

Closed
TimSon777 opened this issue Dec 26, 2023 · 5 comments
Closed

Can't send Http request in IEventHandler #187

TimSon777 opened this issue Dec 26, 2023 · 5 comments
Labels

Comments

@TimSon777
Copy link
Contributor

Hi! We have very strange problem: we can't send http request in Api, where we locate this IEventHandler from IEventHandler (monolith with slack api and business-logic api), because we always get error:

Microsoft.AspNetCore.Server.Kestrel.Core.BadHttpRequestException
Unexpected end of request content.

image

I research it, and we can send these http requests in IBlockActionHandler and custom controllers too:

image

Main difference between these actions: the former respond instantly and process this event in the background, while the latter process it in the moment

I also research it in github and find: dotnet/aspnetcore#23949

image

You have something similar in your code, but everything seems ok. I'm a little confused by OnCompleted in HttpResponse, of course, but it seems to be normal there too. Any ideas?

@soxtoby
Copy link
Owner

soxtoby commented Dec 28, 2023

Hmm... this is strange. I agree the early response with events is potentially suspect, but I haven't had any luck reproducing the issue. By the time the event handler is called, nothing should be accessing the request as far as I can tell.

Is it definitely throwing during the PostAsJsonAsync call? Could it be something to do with the IHttpClientFactory configuration? I just used a plain .AddHttpClient() call to set it up.

@TimSon777
Copy link
Contributor Author

Sorry, I forgot to provide context. This works locally, but specifically in aws apprunner it does not work. I just thought maybe you know some subtle places in your code that could potentially break something

I used services.AddHttpClient(); too

@soxtoby
Copy link
Owner

soxtoby commented Dec 31, 2023

specifically in aws apprunner it does not work

This could be similar to what I hit with Azure Functions then - the app is only meant to run for the length of the request, and handlers running after the request completes were failing. I'm not familiar with App Runner, but if it operates similarly, then the solution may be the same - delay the response until the handler has completed.

Unfortunately I only put that functionality into the Functions integration - I'll try to get a new version up in the next few days that provides the same option for ASP.NET.

@soxtoby
Copy link
Owner

soxtoby commented Jan 2, 2024

v0.12.1 has the new option. Enable it with:

app.UseSlackNet(c => c.DelayResponse())

I've marked it as obsolete with a note about it being experimental, because the early response behaviour itself is experimental, and once I finally getting around to finishing that off, there shouldn't be a need for this option any more.

Give that a try and let me know if it works.

Copy link

stale bot commented Mar 2, 2024

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Mar 2, 2024
@stale stale bot closed this as completed Mar 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants