Harbour.RedisSessionStateStore icon indicating copy to clipboard operation
Harbour.RedisSessionStateStore copied to clipboard

NullReferenceException in ReleaseItemExclusive

Open amanda-mitchell opened this issue 10 years ago • 11 comments

I recently switched from the default session store to RedisSessionStateStore on a site that I maintain. Since doing so, I have seen periodic errors logged with the following form:

System.NullReferenceException: Object reference not set to an instance of an object.
   at Harbour.RedisSessionStateStore.RedisSessionStateStoreProvider.ReleaseItemExclusive(HttpContext context, String id, Object lockId) in d:\Repositories\Harbour.RedisSessionStateStore\src\Harbour.RedisSessionStateStore\RedisSessionStateStoreProvider.cs:line 367
   at System.Web.SessionState.SessionStateModule.OnReleaseState(Object source, EventArgs eventArgs)
   at System.Web.HttpApplication.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

If the line number indicated by the stack trace is accurate, the only thing I see that could cause a NullReferenceException is the cast of lockId to an int, although I am not familiar enough with session state stores to know why this would be the case.

amanda-mitchell avatar Aug 10 '14 21:08 amanda-mitchell

Hi @david-mitchell,

What sort of environment are you running your application under? Is there anything else surrounding the error? Can you run it locally and reproduce with the same issues?

TheCloudlessSky avatar Aug 11 '14 00:08 TheCloudlessSky

The application is running on three load balanced nodes running Windows Server 2008 R2 Standard; collectively, the application receives between 1360 and 2450 requests per minute. The entire stack trace in the issue report. The error occurs with a variety of routes, but does not happen on every request.

Because I haven't found a common thread between failing requests, I have not been able to reproduce the issue locally.

amanda-mitchell avatar Aug 11 '14 16:08 amanda-mitchell

Could you try compiling the library yourself and referencing it in your project? You may get more accurate stack trace. The cast from the lockId to int shouldn't give a NRE, if anything it should give an InvalidCastException.

TheCloudlessSky avatar Aug 12 '14 12:08 TheCloudlessSky

I can try it, but I'm pretty sure the stack trace is going to be the same.

Also, casting null to int definitely results in a NullReferenceException.

amanda-mitchell avatar Aug 12 '14 15:08 amanda-mitchell

Right - I wasn't aware that you're getting a null lockId. Even in the samples to create a SessionStateStoreProvider, they use a non-null integer lockId.

Also, it'd help if you injected some more logging statements in that method so that we can capture everything (including the context, id, and lockId). It shouldn't be null...

TheCloudlessSky avatar Aug 12 '14 15:08 TheCloudlessSky

Assuming that the line number on the stack trace is accurate, I'm pretty sure that lockId must be null—there's nothing else on that line (or even in that method) that could result in a NullReferenceException.

Although I'm still mystified as to how it's occurring in the first place.

amanda-mitchell avatar Aug 12 '14 15:08 amanda-mitchell

Right. So, do you think you could add some extra log statements in there so we can try to figure out what's going on?

TheCloudlessSky avatar Aug 12 '14 16:08 TheCloudlessSky

RedisSessionStateStoreProvider line 364 Here Session is null state.Timeout = context.Session.Timeout;

barankaynak avatar Apr 06 '15 07:04 barankaynak

@barankaynak I'm guessing that's because of #26 which was very recently added (but it could be related). How the heck is Session null inside of the SessionStateProvider. Anyways, Looks like I'm going to have to check for nulls there and fix it (or if you have a PR I'd be glad to accept it).

TheCloudlessSky avatar Apr 06 '15 12:04 TheCloudlessSky

Version 1.3.0 is working very well, but 1.4.0 is giving error. When I put a byte[] array into the session it gives Object reference not set to an instance of an object.

barankaynak avatar Aug 03 '15 08:08 barankaynak

I have the same problem. On Redis monitor the library execute this:

1490206496.070684 [0 127.0.0.1:58014] "HGETALL" "RedisSessionStateProvider:iellbpzmnjzoxjzkqfytxhyb" 1490206496.071864 [0 127.0.0.1:58014] "WATCH" "RedisSessionStateProvider:iellbpzmnjzoxjzkqfytxhyb:lock" 1490206496.071927 [0 127.0.0.1:58014] "GET" "RedisSessionStateProvider:iellbpzmnjzoxjzkqfytxhyb:lock" 1490206496.072372 [0 127.0.0.1:58014] "MULTI" 1490206496.072402 [0 127.0.0.1:58014] "DEL" "RedisSessionStateProvider:iellbpzmnjzoxjzkqfytxhyb:lock" 1490206496.072442 [0 127.0.0.1:58014] "EXEC" 1490206496.076770 [0 127.0.0.1:58014] "SETNX" "RedisSessionStateProvider:iellbpzmnjzoxjzkqfytxhyb:lock" ""\xbf\xd2X\x00\x00\x00\x00"

Sometimes, over and over again

ferrt123 avatar Mar 22 '17 18:03 ferrt123