We are using AWS DynamoDB Session State Provider ver 3.1.0.2. The provider is just used out of the box (added via NuGet, enabled via Web.config). Application server is Amazon EC2 instance.
From time to time (very rare) we observe request processing failures. The error log shows following stack trace:
[KeyNotFoundException: The given key was not present in the dictionary.]
Amazon.DynamoDBv2.DocumentModel.Document.get_Item(String key) +86
Amazon.SessionProvider.DynamoDBSessionStateStore.GetSessionStoreItem(Boolean lockRecord, HttpContext context, String sessionId, Boolean& locked, TimeSpan& lockAge, Object& lockId, SessionStateActions& actionFlags) +1171
Amazon.SessionProvider.DynamoDBSessionStateStore.GetItem(HttpContext context, String sessionId, Boolean& locked, TimeSpan& lockAge, Object& lockId, SessionStateActions& actionFlags) +275
System.Web.SessionState.SessionStateModule.GetSessionStateItem() +96
System.Web.SessionState.SessionStateModule.BeginAcquireState(Object source, EventArgs e, AsyncCallback cb, Object extraData) +1053
System.Web.AsyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +12335126
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +288
We can't reproduce such failures. I've tried figure out the reason of such error and I found that session objects in the DynamoDB has following structure in all cases when such error occurs:
I've looked at sources of the GetSessionStoreItem method and assumed that either DateTime expire = (DateTime)session[ATTRIBUTE_EXPIRES]
or session[ATTRIBUTE_LOCK_DATE] != null
may cause such exception. So, I made manual changes in the session objects directly on the DynamoDB as follow:
{
"Expires": "2015-12-01T21:13:51.474Z",
"Locked": 0,
"SessionId": "zdzfgxacwkwdig0oopcnuxz3",
"LockDate": "2015-12-01T20:13:51.474Z"
}
And that resolved the issue. The subsequent request rewrite the session object as follow:
{
"Expires": "2015-12-01T23:44:01.395Z",
"LockDate": "2015-12-01T22:43:05.250Z",
"Locked": 0,
"LockId": "47741919-bde7-4450-8fc5-71f581964d66",
"SessionId": "zdzfgxacwkwdig0oopcnuxz3"
}
Such fix has been applied multiple time and always solve the issue. What is still a question - why such situation occurs at all.