-
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
NullReferenceException in get_RequestAborted from SystemTextJsonOutputFormatter.WriteResponseBodyAsync #55484
Comments
Has I said, this problem is quite sporadic. I'm not sure I'd be able to provide a minimal reproduction for this without more information. |
Some more context would be useful though - like what code is trying to call this method in your application. Is it an MVC action, if so how is it defined? Are you trying to do some work in a background thread after the request has ended by accessing the There's lots of things your application is doing that might cause this through incorrect usage, rather than it being a bug. Even if you can't make the bug happen, if you can provide some code showing what your application does, any incorrect usage could be spotted. There's no much to go on in the stack trace by itself that's actionable to something specific. |
Hey @martincostello the problem is that it's part of large codebase with dozens of endpoints, I'm not sure what exactly I can include. The stacktrace starts at the I'm more surprised there's a NRE and not a proper exception such as something like "trying to access httpcontext after it has been disposed". |
It looks to me like the stack trace has been truncated, or if it isn't that it is maybe running on a background thread. The thing that's missing here is that it isn't obvious why something is trying to access I would imagine that the reason there's a NRE happening is because of something to do with threading and there's a race-condition happening causing it, which is why there's not an specific exception handling around it (because it shouldn't happen in the first place). |
+1 to @martincostello's comments here. I appreciate that it might be challenging to create a repro particularly for issues like this but additional details will be useful in debugging. Are you hitting this in production? If so, do you have additional logs around the exception? Do you have any hints as to what type of requests might have resulted in this issue? How frequently does it occur? |
Hey @captainsafia, Yes, we're hitting in production. Sadly I don't have more logs and couldn't figure out the circumstances that caused the issue :/ |
Is there an existing issue for this?
Describe the bug
NullReferenceException insides
WriteRespondeBodyAsync
.Expected Behavior
No exception
Steps To Reproduce
N/A it happens sporadically
Exceptions (if any)
System.NullReferenceException: Object reference not set to an instance of an object.
at Microsoft.AspNetCore.Http.DefaultHttpContext.get_RequestAborted()
at Microsoft.AspNetCore.Mvc.Formatters.SystemTextJsonOutputFormatter.WriteResponseBodyAsync(OutputFormatterWriteContext context, Encoding selectedEncoding)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Awaited|30_0[TFilter,TFilterAsync](ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResultExecutedContextSealed context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.ResultNext[TFilter,TFilterAsync](State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeResultFilters()
--- End of stack trace from previous location ---
.NET Version
8.0
Anything else?
No response
The text was updated successfully, but these errors were encountered: