Skip to content

Commit 1630641

Browse files
authored
V1.1 update (#2)
V1.1 update
1 parent e8037c6 commit 1630641

25 files changed

+1597
-522
lines changed

src/SessionStateModule/AppSettings.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ private static void LoadSettings(NameValueCollection appSettings)
2222
{
2323
_requestQueueLimitPerSession = DefaultRequestQueueLimitPerSession;
2424
}
25+
26+
//
27+
// AllowConcurrentRequests
28+
//
29+
string allowConcurrentRequestPerSession = appSettings["aspnet:AllowConcurrentRequestsPerSession"];
30+
bool.TryParse(allowConcurrentRequestPerSession, out _allowConcurrentRequestsPerSession);
2531
}
2632

2733
private static void EnsureSettingsLoaded()
@@ -62,5 +68,15 @@ public static int RequestQueueLimitPerSession
6268
return _requestQueueLimitPerSession;
6369
}
6470
}
71+
72+
private static bool _allowConcurrentRequestsPerSession = false;
73+
public static bool AllowConcurrentRequestsPerSession
74+
{
75+
get
76+
{
77+
EnsureSettingsLoaded();
78+
return _allowConcurrentRequestsPerSession;
79+
}
80+
}
6581
}
6682
}

src/SessionStateModule/InProcSessionStateStoreAsync.cs

Lines changed: 3 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -161,36 +161,7 @@ public override Task RemoveItemAsync(
161161
throw new ArgumentException(SR.Session_id_too_long);
162162
}
163163

164-
var lockCookie = (int)lockId;
165-
var state = (InProcSessionState)s_store.Get(id);
166-
167-
if(state != null)
168-
{
169-
bool lockTaken = false;
170-
171-
try
172-
{
173-
state.SpinLock.Enter(ref lockTaken);
174-
175-
// Only remove the item if we are the owner
176-
if(!state.Locked || state.LockCookie != lockCookie)
177-
{
178-
return Task.CompletedTask;
179-
}
180-
181-
// prevent overwriting when we drop the lock
182-
state.LockCookie = 0;
183-
}
184-
finally
185-
{
186-
if(lockTaken)
187-
{
188-
state.SpinLock.Exit();
189-
}
190-
}
191-
192-
s_store.Remove(id);
193-
}
164+
s_store.Remove(id);
194165

195166
return Task.CompletedTask;
196167
}
@@ -253,11 +224,6 @@ public override Task SetAndReleaseItemExclusiveAsync(
253224
try
254225
{
255226
currentState.SpinLock.Enter(ref lockTaken);
256-
// Only set the state if we are the owner
257-
if(!currentState.Locked || currentState.LockCookie != lockCookie)
258-
{
259-
return Task.CompletedTask;
260-
}
261227

262228
// we can change the state in place if the timeout hasn't changed
263229
if(currentState.Timeout == item.Timeout)
@@ -278,14 +244,7 @@ Please note that the item itself should not expire between now and
278244
updated its expiry time.
279245
*/
280246
currentState.Flags |= (int)SessionStateItemFlags.IgnoreCacheItemRemoved;
281-
282-
/* By setting _lockCookie to 0, we prevent an overwriting by ReleaseExclusive
283-
when we drop the lock.
284-
The scenario can happen if another request is polling and trying to prempt
285-
the lock we have on the item.
286-
*/
287247
lockCookieForInsert = lockCookie;
288-
currentState.LockCookie = 0;
289248
}
290249
}
291250
finally
@@ -346,12 +305,7 @@ private Task<GetItemResult> DoGetAsync(HttpContextBase context, string id, bool
346305
SessionStateActions actionFlags;
347306

348307
var item = DoGet(context, id, exclusive, out locked, out lockAge, out lockId, out actionFlags);
349-
GetItemResult result = null;
350-
351-
if (item != null)
352-
{
353-
result = new GetItemResult(item, locked, lockAge, lockId, actionFlags);
354-
}
308+
GetItemResult result = new GetItemResult(item, locked, lockAge, lockId, actionFlags);
355309

356310
return Task.FromResult<GetItemResult>(result);
357311
}
@@ -472,7 +426,7 @@ private void InsertToCache(string key, InProcSessionState value)
472426
RemovedCallback = _callback,
473427
Priority = CacheItemPriority.NotRemovable
474428
};
475-
s_store.Add(key, value, cachePolicy);
429+
s_store.Set(key, value, cachePolicy);
476430
}
477431

478432
private SessionStateStoreData CreateLegitStoreData(

src/SessionStateModule/SessionStateModuleAsync.cs

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,11 @@ private async Task CompleteAcquireStateAsync(HttpContext context)
576576
OnStart(EventArgs.Empty);
577577
}
578578

579-
RegisterEnsureStateStoreItemLocked();
579+
// lock free session doesn't need this
580+
if(!AppSettings.AllowConcurrentRequestsPerSession)
581+
{
582+
RegisterEnsureStateStoreItemLocked();
583+
}
580584
}
581585
finally
582586
{
@@ -653,7 +657,7 @@ private async Task GetSessionStateItemAsync()
653657

654658
Debug.Assert(_rqId != null, "_rqId != null");
655659

656-
if (_rqReadonly)
660+
if (_rqReadonly || AppSettings.AllowConcurrentRequestsPerSession)
657661
{
658662
GetItemResult result = await _store.GetItemAsync(_rqContext, _rqId, GetCancellationToken());
659663
if (result != null)
@@ -701,7 +705,7 @@ private async Task GetSessionStateItemAsync()
701705
QueueRef();
702706
isQueued = true;
703707
}
704-
// TODO: The retry timeout should be configurable.
708+
705709
if (lockAge >= _rqExecutionTimeout)
706710
{
707711
/* Release the lock on the item, which is held by another thread*/
@@ -786,15 +790,7 @@ private static void LookUpRegForPollInterval()
786790
}
787791
}
788792
}
789-
790-
// Called by OnReleaseState to get the session id.
791-
private string ReleaseStateGetSessionId()
792-
{
793-
Debug.Assert(_rqId != null, "_rqId != null");
794-
return _rqId;
795-
}
796-
797-
793+
798794
// Release session state
799795
private Task ReleaseStateAsync(HttpApplication application)
800796
{
@@ -849,15 +845,15 @@ private async Task ReleaseStateAsyncImpl(HttpApplication application)
849845
// we need to explicitly call Session_End.
850846
if (_supportSessionExpiry)
851847
{
852-
_onEndTarget.RaiseSessionOnEnd(ReleaseStateGetSessionId(), _rqItem);
848+
_onEndTarget.RaiseSessionOnEnd(_rqId, _rqItem);
853849
}
854850
}
855851
else
856852
{
857853
Debug.Assert(_rqItem != null, "_rqItem cannot null if it's not a new session");
858854

859855
// Remove it from the store because the session is abandoned.
860-
await _store.RemoveItemAsync(_rqContext, ReleaseStateGetSessionId(), _rqLockId, _rqItem, GetCancellationToken());
856+
await _store.RemoveItemAsync(_rqContext, _rqId, _rqLockId, _rqItem, GetCancellationToken());
861857
}
862858
}
863859
else if (!_rqReadonly ||
@@ -882,8 +878,7 @@ private async Task ReleaseStateAsyncImpl(HttpApplication application)
882878
}
883879

884880
setItemCalled = true;
885-
await
886-
_store.SetAndReleaseItemExclusiveAsync(_rqContext, ReleaseStateGetSessionId(), _rqItem,
881+
await _store.SetAndReleaseItemExclusiveAsync(_rqContext, _rqId, _rqItem,
887882
_rqLockId, _rqSessionStateNotFound, GetCancellationToken());
888883
}
889884
else
@@ -892,8 +887,7 @@ private async Task ReleaseStateAsyncImpl(HttpApplication application)
892887
if (!_rqSessionStateNotFound)
893888
{
894889
Debug.Assert(_rqItem != null, "_rqItem cannot null if it's not a new session");
895-
await
896-
_store.ReleaseItemExclusiveAsync(_rqContext, ReleaseStateGetSessionId(), _rqLockId,
890+
await _store.ReleaseItemExclusiveAsync(_rqContext, _rqId, _rqLockId,
897891
GetCancellationToken());
898892
}
899893
}

src/SqlSessionStateProviderAsync/App.config

Lines changed: 0 additions & 13 deletions
This file was deleted.

src/SqlSessionStateProviderAsync/Entities/ModelHelper.cs

Lines changed: 0 additions & 98 deletions
This file was deleted.

src/SqlSessionStateProviderAsync/Entities/Session.cs

Lines changed: 0 additions & 23 deletions
This file was deleted.

src/SqlSessionStateProviderAsync/Entities/SessionContext.cs

Lines changed: 0 additions & 23 deletions
This file was deleted.

0 commit comments

Comments
 (0)