TheCloudlessSky / Harbour.RedisSessionStateStore

A Redis based SessionStateStoreProvider written in C# using ServiceStack.Redis.
MIT License
166 stars 76 forks source link

NullReferenceException in ReleaseItemExclusive #23

Open amanda-mitchell opened 10 years ago

amanda-mitchell commented 10 years ago

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.

TheCloudlessSky commented 10 years ago

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?

amanda-mitchell commented 10 years ago

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.

TheCloudlessSky commented 10 years ago

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.

amanda-mitchell commented 10 years ago

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.

TheCloudlessSky commented 10 years ago

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...

amanda-mitchell commented 10 years ago

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.

TheCloudlessSky commented 10 years ago

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?

barankaynak commented 9 years ago

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

TheCloudlessSky commented 9 years ago

@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).

barankaynak commented 9 years ago

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.

ferrt123 commented 7 years ago

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