aspnet / AspNetKatana

Microsoft's OWIN implementation, the Katana project
Apache License 2.0
959 stars 331 forks source link

System.NullReferenceException: Object reference not set to an instance of an object #511

Closed jthorpe80 closed 9 months ago

jthorpe80 commented 10 months ago

We occasionally see this exception, more so during heavier traffic. Never been able to reproduce during testing. Using latest Microsoft.Owin nuget packages (4.2.2)

System.InvalidOperationException ---> System.NullReferenceException: Object reference not set to an instance of an object. at Microsoft.Owin.Host.SystemWeb.CallHeaders.SendingHeadersEvent.Fire() in at Microsoft.Owin.Host.SystemWeb.OwinCallContext.StartOnce() in --- End of inner exception stack trace --- at Microsoft.Owin.Host.SystemWeb.OwinCallContext.OnStart() in at Microsoft.Owin.Host.SystemWeb.OwinCallContext.OnEnd() in --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at Microsoft.Owin.Host.SystemWeb.CallContextAsyncResult.End(IAsyncResult result) in at Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.IntegratedPipelineContext.d__12.MoveNext() in --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.StageAsyncResult.End(IAsyncResult ar) in at System.Web.HttpApplication.AsyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() at System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step) at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

Tratcher commented 10 months ago

Hmm, that code is pretty hardened... https://github.com/aspnet/AspNetKatana/blob/3c194663090eeea35e5ee95cbe54959e0b90e3e3/src/Microsoft.Owin.Host.SystemWeb/CallHeaders/SendingHeadersEvent.cs#L10-L37

Could somebody be calling OnSendingHeaders with a null Action callback? https://github.com/aspnet/AspNetKatana/blob/3c194663090eeea35e5ee95cbe54959e0b90e3e3/src/Microsoft.Owin.Host.SystemWeb/CallHeaders/SendingHeadersEvent.cs#L34C2-L34C2

jthorpe80 commented 10 months ago

I'm not sure. This started after some Nuget packages were added. Is there a way to trace it back to the offending caller? Also, shouldn't line 26 also contain a check for a null action callback?

Tratcher commented 10 months ago

A null check or conditional break point on line 20 would be the quickest way to identify the problematic caller. Want to submit a PR?

jthorpe80 commented 10 months ago

I know nothing of this OWIN codebase and am not really qualified to do a PR. Are you saying a PR is the only way the issue would be fixed, or it would be a nice to have?

jthorpe80 commented 10 months ago

Thank you. Is there a release date for 4.2.3?

Tratcher commented 10 months ago

Not yet. There should be nightly builds you can test though to see if this fixes it.

jthorpe80 commented 10 months ago

I don't think that is possible. I've never been able to reproduce. I only see the error in production.

Tratcher commented 10 months ago

Are you willing to deploy the nightly builds into production? It's the same bits other than the version number.

jthorpe80 commented 10 months ago

It would be a tough sell. This is a government system with the usual red tape.