Skip to content

Commit

Permalink
[asp.net] Fix for bug #669807. Cache session item locks as the item m…
Browse files Browse the repository at this point in the history
…ight be cleared before the lock needs to be released.
  • Loading branch information
grendello committed Feb 21, 2011
1 parent e09f898 commit 01e4a9b
Showing 1 changed file with 22 additions and 11 deletions.
Expand Up @@ -254,17 +254,20 @@ public override void InitializeRequest (HttpContext context)
return;

bool locked = false;
ReaderWriterLockSlim itemLock = null;

try {
if (item.rwlock.TryEnterWriteLock (lockAcquireTimeout))
itemLock = item.rwlock;
if (itemLock != null && itemLock.TryEnterWriteLock (lockAcquireTimeout))
locked = true;
else
throw new ApplicationException ("Failed to acquire lock");
item.locked = false;
} catch {
throw;
} finally {
if (locked)
item.rwlock.ExitWriteLock ();
if (locked && itemLock != null)
itemLock.ExitWriteLock ();
}
}

Expand All @@ -282,8 +285,11 @@ public override void InitializeRequest (HttpContext context)
return;

bool locked = false;
ReaderWriterLockSlim itemLock = null;

try {
if (inProcItem.rwlock.TryEnterWriteLock (lockAcquireTimeout))
itemLock = inProcItem.rwlock;
if (itemLock != null && itemLock.TryEnterWriteLock (lockAcquireTimeout))
locked = true;
else
throw new ApplicationException ("Failed to acquire lock after");
Expand All @@ -292,7 +298,7 @@ public override void InitializeRequest (HttpContext context)
throw;
} finally {
if (locked)
inProcItem.rwlock.ExitWriteLock ();
itemLock.ExitWriteLock ();
}
}

Expand All @@ -307,8 +313,11 @@ public override void ResetItemTimeout (HttpContext context, string id)
return;

bool locked = false;
ReaderWriterLockSlim itemLock = null;

try {
if (item.rwlock.TryEnterWriteLock (lockAcquireTimeout))
itemLock = item.rwlock;
if (itemLock != null && itemLock.TryEnterWriteLock (lockAcquireTimeout))
locked = true;
else
throw new ApplicationException ("Failed to acquire lock after");
Expand All @@ -318,8 +327,8 @@ public override void ResetItemTimeout (HttpContext context, string id)
} catch {
throw;
} finally {
if (locked)
item.rwlock.ExitWriteLock ();
if (locked && itemLock != null)
itemLock.ExitWriteLock ();
}
}

Expand Down Expand Up @@ -366,8 +375,10 @@ public override void ResetItemTimeout (HttpContext context, string id)
}

bool locked = false;
ReaderWriterLockSlim itemLock = null;
try {
if (inProcItem.rwlock.TryEnterWriteLock (lockAcquireTimeout))
itemLock = inProcItem.rwlock;
if (itemLock != null && itemLock.TryEnterWriteLock (lockAcquireTimeout))
locked = true;
else
throw new ApplicationException ("Failed to acquire lock");
Expand All @@ -378,8 +389,8 @@ public override void ResetItemTimeout (HttpContext context, string id)
} catch {
throw;
} finally {
if (locked)
inProcItem.rwlock.ExitWriteLock ();
if (locked && itemLock != null)
itemLock.ExitWriteLock ();
}
}

Expand Down

0 comments on commit 01e4a9b

Please sign in to comment.