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

Potential threading issue when used with AspNetCore #27

Closed
darraghjones opened this issue Nov 2, 2018 · 4 comments
Closed

Potential threading issue when used with AspNetCore #27

darraghjones opened this issue Nov 2, 2018 · 4 comments

Comments

@darraghjones
Copy link

darraghjones commented Nov 2, 2018

I'm seeing the follow error periodically in my logs....~ 0.5% of requests.

System.NullReferenceException: Object reference not set to an instance of an object.
   at Microsoft.AspNetCore.Http.DefaultHttpContext.get_Items()

I only get this error when the GelfLoggerProvider is added. From what I've read this could be due to accessing the DefaultHttpContext from multiple threads. I've tried disabling scopes to see if that helped, but I still see the error.

I would also like to point out I only notice this when running on AWS ECS.

@NatalyDrobot
Copy link

We have also started to get a similar error, but much more often. Lowering the level of logging to Error has helped a little, but... we still have had to stop using the library, because when increasing the frequency of requests to our API, the frequency of NullReferenceException increases.

The last configuration:

"Logging": { "IncludeScopes": true, "LogLevel": { "Default": "Information" }, "Console": { "LogLevel": { "Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware": "Error", "Microsoft.AspNetCore.Server.Kestrel": "Error", "Microsoft.AspNetCore.Hosting.Internal.WebHost": "Warning", "Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker": "Warning", "Default": "Information" } }, "GELF": { "IncludeScopes": true, "LogLevel": { "Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware": "Error", "Microsoft.AspNetCore.Server.Kestrel": "Error", "Microsoft.AspNetCore.Hosting.Internal.WebHost": "Warning", "Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker": "Warning", "Default": "Information" } }

@mattwcole
Copy link
Owner

Thanks for reporting this. The library pushes logs to an internal queue where they are de-queued and sent from background threads (here) so it does indeed look like a threading issue. @darraghjones something in the scope would be my first thought as well. I haven't seen this with aspnetcore 2.0, this will require some investigation.

@mattwcole
Copy link
Owner

mattwcole commented Nov 16, 2018

We have been able to reproduce the issue with aspnetcore 2.1. It appears to be because of the enumeration of AdditionalFields on the background thread that serializes GelfMessage. The framework appears to put something in the log scope that ultimately touches HttpContext, and this is accessed in the background during the enumeration. We have a fix that seems to be working - I will include this in a new release over the weekend.

@mattwcole
Copy link
Owner

I've just pushed v1.5.0-pre1 to nuget.org with an update that should fix this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants