Bug #52175 Connector/Net throws exception and keeps session locked
Submitted: 18 Mar 2010 11:03 Modified: 22 Apr 2010 12:50
Reporter: Steve Hammond Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / NET Severity:S3 (Non-critical)
Version:6.2.2 OS:Any
Assigned to: Vladislav Vaintroub CPU Architecture:Any
Tags: Connector/Net, locked, session, SqlNullValueException

[18 Mar 2010 11:03] Steve Hammond
Description:
Periodically the session provider will throw an SqlNullValueException exception.
When it does this, the row within the my_aspnet_Sessions table has 'locked' always set to '1', the locked status never changes back to '0' and the user will experience the exception on every page - until they close the browser and open it again (recreating a new sessionID) - or the 'locked' value is manually changed to '0'.

We have been experiencing this on both our development environment and the production system.

I've spent the best part of a week trying to make a test case, I've tried many things including:

Quickly creating / adding / amending / deleting lots session vars
Adding large serialised data objects to the session
Adding lots of session variables over and over again

I can't seem to make the provider break on demand, but with our production website (3000 users a day average) I get anywhere from 3 - 20 cases of this happening.  We can go weeks with only 3-4 a day then one day get 20+ but back to only 3-4 the next.

I've been logging page hits, usage and performance counters on the web servers to try and identify what is different when we have a large number of cases, however nothing really differs - that I can see.

To help identify if the provider was causing it, our source code or even objects we stored within the session I changed our development system to use MSSQL and we didn't have the exception once.

There was a thread started Jan 11th 2010 in the forums, I see not many people have added to say they are having the same issues, but as I'm fairly confident that this is the provider and not our website code I thought I would post a bug request.

I'm frustrated at not getting to the bottom of what is actually causing the provider to lock the row and not unlock it again, after reading the first post in the forum I thought the asp.net process might be crashing but performance logging shows its not.

Forum URL is: http://forums.mysql.com/read.php?38,298820,298820#msg-298820

Here is the exception:
Server Error in '/' Application.
--------------------------------------------------------------------------------
Data is Null. This method or property cannot be called on Null values. 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.Data.SqlTypes.SqlNullValueException: Data is Null. This method or property cannot be called on Null values.

Source Error: 
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.  

Stack Trace: 
[SqlNullValueException: Data is Null. This method or property cannot be called on Null values.]
   MySql.Data.MySqlClient.MySqlDataReader.GetFieldValue(Int32 index, Boolean checkNull) +146
   MySql.Data.MySqlClient.MySqlDataReader.GetInt32(Int32 i) +33
   MySql.Web.SessionState.MySqlSessionStateStore.GetSessionStoreItem(Boolean lockRecord, HttpContext context, String id, Boolean& locked, TimeSpan& lockAge, Object& lockId, SessionStateActions& actionFlags) +887
   MySql.Web.SessionState.MySqlSessionStateStore.GetItemExclusive(HttpContext context, String id, Boolean& locked, TimeSpan& lockAge, Object& lockId, SessionStateActions& actions) +55
   System.Web.SessionState.SessionStateModule.GetSessionStateItem() +185
   System.Web.SessionState.SessionStateModule.PollLockedSessionCallback(Object state) +245

[HttpException (0x80004005): Exception of type 'System.Web.HttpException' was thrown.]
   System.Web.SessionState.SessionStateModule.EndAcquireState(IAsyncResult ar) +11155956
   System.Web.AsyncEventExecutionStep.OnAsyncEventCompletion(IAsyncResult ar) +101

How to repeat:
Please see the description, I cannot make it happen every time within a test case.

Suggested fix:
Identify a possible reason
[19 Mar 2010 13:36] Steve Hammond
I'm still trying to make a test case to break it.

However looking from another perspective I can produce the error on command, just not via source code.

If you manually update the database and set lockid to 1 you will see the error.

UPDATE my_aspnet_Sessions
SET Lockid = 1

After this try and access any of the stored sessions and the error will show
[7 Apr 2010 8:26] Tonci Grgin
Hi Steve and thanks for your report.

Setting LockId by hand does not seem a proper way to repeat this problem but I will not dismiss your report just yet. Although I see no way to make a proper test case that will expose the error.
[8 Apr 2010 7:22] Tonci Grgin
Steve, I've consulted and your workaround for reproducing the problem should be valid.

Now, I'd like you to attach a small test case with this
  UPDATE my_aspnet_Sessions SET Lockid = 1
and everything so I can test.
[21 Apr 2010 13:27] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/106259

829 Vladislav Vaintroub	2010-04-21
      SessionProvider : Avoid SQLNullValueException if lockId returned by select is NULL (bug#52175)
[21 Apr 2010 14:08] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/106262

847 Vladislav Vaintroub	2010-04-21
      SessionProvider : Avoid SQLNullValueException if lockId returned by select is NULL (bug#52175)
[21 Apr 2010 14:10] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/106263

847 Vladislav Vaintroub	2010-04-21
      SessionProvider : Avoid SQLNullValueException if lockId returned by select is NULL (bug#52175)
[21 Apr 2010 15:18] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/106274

805 Vladislav Vaintroub	2010-04-21
      SessionProvider : Avoid SQLNullValueException if lockId returned by select is 
       NULL (bug#52175)
[22 Apr 2010 12:50] Tony Bedford
An entry has been added to the 6.2.4 changelog:

Periodically the session provider threw an SqlNullValueException exception. When this happened, the row within the my_aspnet_Sessions table had locked always set to '1'. The locked status never changed back to '0' and the user experienced the exception on every page, until their browser was closed and reopened (recreating a new sessionID), or the locked value was manually changed to '0'.