-
Notifications
You must be signed in to change notification settings - Fork 9.8k
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
Static file request missing HTTP method, and therefore rejected #4195
Comments
This is using Kestrel, correct? When we've seen this before it was always caused by async state corruption by the prior request on that connection. Can you pull the logs for the prior request? The common issue is when a background thread holds onto the HttpContext and accesses it inappropriately after the end of the request. This can corrupt resources that are shared with future requests on that connection. |
@Tratcher The page (action= Switchboard) is used multple times, showing slightly different content. The last time loading that page it fails. I was first logging out (SignOutAsync()) before the last time showing that page, but I had already removed that to see if that caused some type of corruption. Here requests that are going to that page, ending with the request that fails.
|
If you look at the Kestrel logs they tell you there are at least two different connections in use. You need to correlate which requests happened on the same connection as the final broken request. |
Though I guess in your example the last requests on both connections for static files. That implies that if there's an async issue then it's in a middleware before static files, or in a logging component. Do you reference HttpContext from any logging code? |
Thanks!
I have now changed this for testing to
And this does not have the problem. So it seems the SendMailAsync method is causing the problem. |
Does SendMailAsync touch HttpContext? |
SendMailAsync just creates the body and sends the mail through MailKit, it does not touch HttpContext (at least not in my code). I now found that an other issue (in another part of the site) we are having is the same, it is a 404 on a Ajax call, caused by missing the HTTP Method on the request. This is also just after sending an other email on a background thread. After awaiting that call, that problem also goes away.
|
Then it's your logging code itself causing the problem. It is logging the request Method, so it's accessing the HttpContext to get that. |
Spot on sir! I removed the wait's on the SendMailAsync , and stopped the request Method logging. Than it works too. So my question is, what is causing this? Should I not have tried to remove the email delay from the UI, or is there something Nlog should look at to do differently? |
Background threads cannot safely access HttpContext. Since logging can sometimes happen on background threads it also cannot access HttpContext. If you really want to log something like the method then pass that value through as a paramter, don't try to read it from ambient thread context. |
Thanks you insight and help is greatly appreciated. |
Describe the bug
A clear and concise description of what the bug is.
I am getting a 404, mostly on one image, however, intermittently, also on others on the same page. This occurs only in debug deployment, not when deploying the Release configuration.
Chrome Console:
GET https://{my domain}/css/images/btn-info.png 404 (Not Found)
Server Log:
Notice the space before " requests are not allowed" and in the line Request starting.... The HTTP method is missing. I assume that this is causing the StaticFileMiddleware to reject the request. But why is this missing?
All other requests in the log have the HTTP method, e.g:
The image is loaded from css:
Startup:
Additional context
Add any other context about the problem here.
ISS on Windows Server 2012 R2
Include the output of
dotnet --info
(on the development PC).NET Core SDK (reflecting any global.json):
Version: 2.1.403
Commit: 04e15494b6
Runtime Environment:
OS Name: Windows
OS Version: 10.0.17134
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\2.1.403\
Host (useful for support):
Version: 2.1.5
Commit: 290303f510
.NET Core SDKs installed:
1.0.0 [C:\Program Files\dotnet\sdk]
1.1.0 [C:\Program Files\dotnet\sdk]
2.1.4 [C:\Program Files\dotnet\sdk]
2.1.103 [C:\Program Files\dotnet\sdk]
2.1.104 [C:\Program Files\dotnet\sdk]
2.1.200 [C:\Program Files\dotnet\sdk]
2.1.201 [C:\Program Files\dotnet\sdk]
2.1.202 [C:\Program Files\dotnet\sdk]
2.1.301 [C:\Program Files\dotnet\sdk]
2.1.302 [C:\Program Files\dotnet\sdk]
2.1.402 [C:\Program Files\dotnet\sdk]
2.1.403 [C:\Program Files\dotnet\sdk]
.NET Core runtimes installed:
Microsoft.AspNetCore.All 2.1.1 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.1 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 1.0.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 1.0.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 1.1.1 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 1.1.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.0.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.0.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.0.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.0.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.1 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
To install additional .NET Core runtimes or SDKs:
https://aka.ms/dotnet-download
The text was updated successfully, but these errors were encountered: