WebForms Application Crashes Due to SessionState Null Reference Exception (NameObjectCollectionBase.BaseRemove)

Alex Weller 1 Reputation point
2021-08-10T00:23:41.36+00:00

Hi,

We have a ASP.NET 4.7.2 WebForms application that we have been installing on-prem for customers for 2+ decades now. In a "managed cloud" strategy that, we are doing a lift-and-shift model where we are running this WebForms application in a VM hosted in Microsoft Azure.

We are doing UAT testing and finding that under certain userload, the web application is crashing. Looking at the logs, we are seeing something that... we have never seen before in the 20+ years we have ran this application. So far, this azure VM is the only environment that we have seen this in.

See the stack trace below. We use SessionState to hold data relevant to the User's workflow they are in. ASP.NET enforces SessionState thread safety with SessionState by restricting request threads to only process one at a time (e.x. two requests come in for the same ASP.NET_SessionId, both do not execute at the same time, one has to wait until the other one finishes). These exceptions are coming out of page requests that should be blocking on SessionState to prevent concurrent access to it.

There is a null reference error that randomly occurs when a value is removed from session. I have been able to find very little online about this. The few articles I do find indicate that this is a concurrency issue and two threads are accessing the same session state value at the same time.

I have tried using jMeter to replicate user load on this same instance and cannot reproduce this issue. I have no known steps to reproduce this other than when they have users in the system, these errors crop up after a while and then the web app crashes (this exception appears to be fatal when it bubbles up).

Any help you can provide would be greatly appreciated.

https://stackoverflow.com/questions/14249269/asp-net-application-throws-system-nullreferenceexception-from-session-remove-imp
https://thegrumpycoder.com/post/167973970736/nullreferenceexception-in-sessionstateitemcollection

08/09/2021 12:11:31 =============================
EXCEPTION: Object reference not set to an instance of an object.
at System.Collections.Specialized.NameObjectCollectionBase.BaseRemove(String name)
at System.Web.SessionState.SessionStateItemCollection.Remove(String name)
at NamespaceTwo.ClassOne.MethodOne(String whereClause)
08/09/2021 12:11:50 =============================
Object reference not set to an instance of an object.
at System.Collections.Specialized.NameObjectCollectionBase.BaseRemove(String name)
at System.Web.SessionState.SessionStateItemCollection.Remove(String name)
at NamespaceOne.PageOne.CleanSession()
at NamespaceOne.PageOne.PrepareWebScreen()
at NamespaceOne.BasePages.MyBasePage.Page_Load(Object sender, EventArgs e)
at System.EventHandler.Invoke(Object sender, EventArgs e)
at System.Web.UI.Control.OnLoad(EventArgs e)
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

08/09/2021 12:11:50 =============================
Object reference not set to an instance of an object.
at System.Collections.Specialized.NameObjectCollectionBase.BaseRemove(String name)
at System.Web.SessionState.SessionStateItemCollection.Remove(String name)
at NamespaceOne.PageTwo.CleanSession()
at NamespaceOne.PageTwo.PrepareWebScreen()
at NamespaceOne.BasePages.MyBasePage.Page_Load(Object sender, EventArgs e)
at System.EventHandler.Invoke(Object sender, EventArgs e)
at System.Web.UI.Control.OnLoad(EventArgs e)
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

08/09/2021 13:17:56 =============================
Object reference not set to an instance of an object.
at System.Collections.Specialized.NameObjectCollectionBase.BaseRemove(String name)
at System.Web.SessionState.SessionStateItemCollection.Remove(String name)
at NamespaceOne.PageThree.PrepareForm()
at NamespaceOne.PageThree.PrepareWebScreen()
at NamespaceOne.BasePages.MyBasePage.Page_Load(Object sender, EventArgs e)
at System.EventHandler.Invoke(Object sender, EventArgs e)
at System.Web.UI.Control.OnLoad(EventArgs e)
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

Edit: Fixing my poor grammar.

ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,219 questions
{count} votes