When using "fat" session (~2MB) and multiple (~20) simultaneous calls
the retrieval sometimes fails and lock the session.
The original code blocks on the calling thread (AutoResetEvent.WaitOne())
and uses another thread with the timer to do the polling.
If the polling succeeds, the TimerCallback AutoResetEvent.Set(),
with no guarantes that it will wake up the thread.
(see Remarks in http://msdn.microsoft.com/en-us/system.threading.eventwaithandle.set%28v=vs.110%29)
In this patch we simply replace all this code with an equivalent
loop + sleep, which give us the same behaviour
(we still block the calling thread with the sleep, but we didn't use another one)
Signed-off-by: Frederic Mestayer <[email protected]>
Signed-off-by: Etienne CHAMPETIER <[email protected]>
SessionStateModule.OnSessionExpired is used as a callback for its
'handler' field (SessionStateStoreProviderBase.SetItemExpireCallback),
and is normaly enabled in Init, as well as disabled in OnReleaseRequestState
if the container is abandoned.
However, since the module may stay around being re-used, it may continue
working *without* this callback being invoked/enabled anymore -causing a number of
nasty, hard to debug side effects, as session data ending up in the void-.
So we enable this callback again in OnAcquireRequestState, which is the
point at where we know we have a brand new, working container.
The in-proc session handler no longer removes and re-inserts an item in order to
update its timeout. It is now done using Cache.SetItemTimeout which, in turn, checks
whether the item being updated is already a timed one and, if yes, calls CacheItemPriorityQueue's
Update method for that item. Should the update fail or the item is not yet timed, the item is
enqueued to the priority queue in the regular fashion.
CacheItem got a new member, PriorityQueueIndex to mark its position in the queue's heap for faster
lookup and manipulation.
The CacheItemPriorityQueue.BubbleDown method was rewritten to properly swap items in the heap.
* System.Web.Caching/CacheItemPriorityQueue.cs: when the heap is resized, the old heap memory
is cleared.
* System.Web.SessionState_2.0/SessionInProcHandler.cs: the session items collection is cleared
when the InProcSessionItem is destroyed
* System.Web/HttpApplicationState.cs: instantiate SessionObjects and StaticObjects collections
only on demand.
Replaced ReaderWriterLock with ReaderWriterLockSlim.
Removed a few variables which aren't needed.
* System.Web/HttpStaticObjectsCollection.cs: replaced a Hashtable with a Dictionary <string, object>.
The objects dictionary is created on demand only.
* Cache.cs: cache removes old/least recently used items when the item count exceeds 15000. Items
are removed until they reach the count of 10000.
* SessionInProcHandler.cs: replaced ReaderWriterLock with ReaderWriterLockSlim and added a Dispose
method to the InProcSessionItem type which disposes the associated lock and other resources.
* Makefile: Compile tests with TEST defined (to include System.Web.Util.
MachineKeySectionUtils unit tests)
* System.Web.dll.sources: Move MachineKeySectionUtils.cs from System.
Web.Configuration_2.0 to System.Web.Util
* System.Web_test.dll.sources: Move MachineKeySectionUtilsTest.cs from
System.Web.Configuration_2.0 to System.Web.Util
* System.Web.Configuration_2.0/MachineKeySection.cs: Adjust using
clauses. Uncomment some code. Fix TripleDES versus 3DES for Validation
under NET_4_0. Remove 'private' on fields/methods.
* System.Web.Handlers/AssemblyResourceLoader.cs: Adjust using clauses
* System.Web.Security/MembershipHelper.cs: Adjust using clauses
* System.Web.Security/RolePrincipal.cs: Adjust using clauses
* System.Web.SessionState_2.0/SessionId.cs: Adjust using clauses
* System.Web.UI/LosFormatter.cs: Adjust using clauses.
* System.Web.Util/MachineKeySectionUtils.cs: Moved from System.Web.
Configuration_2.0. Rename namespace and remove 'internal' on type
declaration
* Test/System.Web.Util/MachineKeySectionUtilsTest.cs: Moved from Test/
System.Web.Configuration/MachineKeySectionTest.cs. Add test case for
TripleDES versus 3DES
* System.Web.Configuration_2.0/MachineKeyRegistryStorage.cs:
Remove key length check and generic key generation.
* System.Web.Configuration_2.0/MachineKeySection.cs: Add support for 4.0
ValidationAlgorithm and the use of custom algorithms (validation and
decryption). Allow the use of any, valid, key length (based on the
algorithm). Let each algorithm creates its own key (e.g. special needs,
default length...)
* System.Web.Configuration_2.0/MachineKeySectionUtils.cs: Remove key
generation (from random) code and 192bits key length hack (won't work
with custom algorithms). Add support for new (4.0) algorithms, including
custom ones. Provide uniform/shared code to Encrypt/Decrypt, Sign/Verify
and EncryptSign/VerifyDecrypt using MachineKeySection data.
* System.Web.Configuration_2.0/MachineKeyValidation.cs: Add new (4.0)
values.
* System.Web.Configuration_2.0/MachineKeyValidationConverter.cs: Add
support for new (4.0) algorithms.
* System.Web.Handlers/AssemblyResourceLoader.cs: Use the new common
cryptographic code and base64 the encrypted data.
* System.Web.Security/FormsAuthentication.cs: Use the new common
cryptographic code and base64 the signed and/or encrypted data.
* System.Web.Security/MembershipHelper.cs: Use the new common
cryptographic code - this should be 100% compatible with existing data.
* System.Web.Security/RolePrincipal.cs: Use the new common cryptographic
code.
* System.Web.Security/SqliteMembershipProvider.cs: Adapt code for
internal API change.
* System.Web.UI/LosFormatter.cs: Adapt code for internal API change.
Fix some small behaviro changes wrt NET_4_0
* System.Web.UI/ObjectStateFormatter.cs: Use the new common cryptographic
code.
* System.Web.UI/Page.cs: Remove code that is now unneeded (with the new
common cryptogrraphic code).
* System.Web.Configuration_2.0/MachineKeyCompatibilityMode.cs: New.
* Test/System.Web.Configuration/MachineKeyValidationConverterTest.cs:
Add more, mostly 4.0, test cases.
* Test/System.Web.Security/FormsAuthenticationTest.cs: Add test case to
ensure HashPasswordForStoringInConfigFile is not case sensitive.
* Test/System.Web.UI/LosFormatterTest.cs: Add some rountrip test cases
with the different ctors
When the in-proc session handler puts items in the internal cache, it prefixes them with the
@@@InProc@ prefix to make sure they don't conflict with other values stored there. The handler
has been failing so far to remove that prefix when triggering the session end event. This commit
fixes the issue.
* BuildManager.cs: do less work in the static constructor
2010-03-04 Marek Habersack <[email protected]>
* RuntimeHelpers.cs: added. Contains methods moved here from
HttpRuntime, so that initialization sequence of various objects is
independent of HttpRuntime.
2010-03-04 Marek Habersack <[email protected]>
* HttpRuntime.cs: do less work in the static constructor. Most of
the code was moved to System.Web.Util.RuntimeHelpers. Properties
which have been moved: MonoVersion, RunningOnWindows,
CaseInsensitive, IsDebuggingEnabled
Also:
- hushed some compiler warnings
- various classes now use RuntimeHelpers instead of HttpRuntime
svn path=/trunk/mcs/; revision=153038
* ASPState.sql: added - schema for the SQL session state server
database.
2009-10-19 Marek Habersack <[email protected]>
* SessionStateModule.cs: enabled SQL session state provider.
* SessionSQLServerHandler.cs: implemented. Uses System.Data.Common
for provider-agnostic implementation. Until an issue with Npgsql's
2.0 factory missing is resolved it defaults to using
Mono.Data.Sqlite as the provider.
Selecting of the data provider is done by putting DbProviderName
in the connection string specified in the
<system.web/sessionState> configuration section.
svn path=/trunk/mcs/; revision=144412
* SessionStateModule.cs: correctly let the handler know if an item
is new when calling SetAndReleaseItemExclusive. Fixes bug #424797
If handler's GetItem doesn't initialize storeLockId to a non-null
value, initialize it to 0. Fixes bug #424797
svn path=/trunk/mcs/; revision=112997
* SessionStateModule.cs: use Request.FilePath instead of
Request.BaseVirtualDirectory to retrieve the cookie-less session
identifier. Fixes bug #397418
2008-07-29 Marek Habersack <[email protected]>
* UrlUtils.cs: fixed a typo in HasSessionId which made it always
return False. Fixes bug #397418
2008-07-29 Marek Habersack <[email protected]>
* SessionStateModule.cs: use Request.FilePath instead of
Request.BaseVirtualDirectory to retrieve the cookie-less session
identifier. Fixes bug #397418
2008-07-29 Marek Habersack <[email protected]>
* HttpRequest.cs: if the FilePath contains embedded cookie-less
session identifier, remove it before computing the base virtual
directory. Fixes bug #397418
svn path=/trunk/mcs/; revision=109156
* SessionStateModule.cs: set the application modifier path to bare
session id.
2008-06-04 Marek Habersack <[email protected]>
* UrlUtils.cs: added internal method HasSessionId
2008-06-04 Marek Habersack <[email protected]>
* SessionStateModule.cs: set application path modifier string to
the bare session ID.
2008-06-04 Marek Habersack <[email protected]>
* HttpResponse.cs: correctly modify virtual path to include the
session ID in cookieless session mode. Fixes bug #396628.
svn path=/trunk/mcs/; revision=104861
* BaseDataBoundControl.cs, ChangePassword.cs, CustomValidator.cs,
DataControlFieldCollection.cs, DataControlField.cs,
PasswordRecovery.cs, PagerSettings.cs: do not use synthetized
event accessors (to avoid locks).
2008-05-30 Marek Habersack <[email protected]>
* AnonymousIdentificationModule.cs, FormsAuthenticationModule.cs,
DefaultAuthenticationModule.cs, MembershipProvider.cs,
WindowsAuthenticationModule.cs, PassportAuthenticationModule.cs,
RoleManagerModule.cs: do not use synthetized event accessors (to
avoid locks).
2008-05-30 Marek Habersack <[email protected]>
* HttpApplication.cs, HttpCachePolicy.cs, SiteMapProvider.cs,
TraceContext.cs: do not use synthetized event accessors (to avoid
locks).
2008-05-30 Marek Habersack <[email protected]>
* SessionStateModule.cs: do not use synthetized event accessors
(to avoid locks).
2008-05-30 Marek Habersack <[email protected]>
* ProfileModule.cs: do not use synthetized event accessors (to
avoid locks).
2008-05-30 Marek Habersack <[email protected]>
* SessionStateModule.cs: do not use synthetized event accessors
(to avoid locks).
2008-05-30 Marek Habersack <[email protected]>
* DataBindingCollection.cs, ExpressionBindingCollection.cs: do not
use synthetized event accessors (to avoid locks).
2008-05-30 Marek Habersack <[email protected]>
* ClientBuildManager.cs: do not use synthetized event accessors
(to avoid locks).
2008-05-30 Marek Habersack <[email protected]>
* CacheDependency.cs: do not use synthetized event accessors (to
avoid locks).
svn path=/trunk/mcs/; revision=104569
* SessionStateModule.cs: reset the storage data item timeout to
the HttpApplication.Session.Timeout value after the Session_Start
event is fired. Fixes bug #382644
svn path=/trunk/mcs/; revision=101632
* SessionStateModule.cs: use TimeSpan.TotalMinutes wherever a
session timeout is required, so that sessions do not expire
prematurely. Fixes bug #339026. Patch from Adriaan van Kekem
<[email protected]>, thanks!
svn path=/trunk/mcs/; revision=88845
* SessionInProcHandler.cs: in certain situations the 'item'
parameter passed to SetAndReleaseItemExclusive may be null. The
issue was reported in bug #333898, but the reporter cannot provide
a test case that triggers the issue. Added work around the problem
in the way that should have the least impact on the rest of the
code. If 'item' is null, then the new session item is created
without the items and staticItems collections - they will be
initialized to defaults when retrieving the session item. This is
not a correct fix, but since there is no test case this is the
best what can be done right now.
svn path=/trunk/mcs/; revision=87636