【问题标题】:MySQL Session state provider crashes on expired sessionsMySQL 会话状态提供程序在过期会话上崩溃
【发布时间】:2013-08-26 04:23:45
【问题描述】:

我有一个使用 MySQL 连接器 6.7.4 在 IIS 7.5 ASP.NET 4 中运行的站点,我正在尝试将其设置为在我的数据库中存储会话状态。 开始时效果很好(我可以存储状态)。但是当我长时间打开浏览器然后尝试刷新页面时,我收到以下错误:


键“PRIMARY”的重复条目“jouwlxjdufet2fyvf4cwefn2-1”

描述:An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

异常详情:

MySql.Data.MySqlClient.MySqlException: Duplicate entry 'jouwlxjdufet2fyvf4cwefn2-1' for key 'PRIMARY'

来源错误:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

堆栈跟踪:

[MySqlException (0x80004005): Duplicate entry 'jouwlxjdufet2fyvf4cwefn2-1' for key 'PRIMARY']
   MySql.Data.MySqlClient.MySqlStream.ReadPacket() +492
   MySql.Data.MySqlClient.NativeDriver.GetResult(Int32& affectedRow, Int64& insertedId) +450
   MySql.Data.MySqlClient.Driver.NextResult(Int32 statementId, Boolean force) +136
   MySql.Data.MySqlClient.MySqlDataReader.NextResult() +1121
   MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior) +2648
   MySql.Data.MySqlClient.MySqlCommand.ExecuteNonQuery() +140
   MySql.Web.SessionState.MySqlSessionStateStore.CreateUninitializedItem(HttpContext context, String id, Int32 timeout) +553

[ProviderException: An exception occurred. Please check the event log.]
   MySql.Web.SessionState.MySqlSessionStateStore.HandleMySqlException(MySqlException e, String action) +281
   MySql.Web.SessionState.MySqlSessionStateStore.CreateUninitializedItem(HttpContext context, String id, Int32 timeout) +709
   System.Web.SessionState.SessionStateModule.GetSessionStateItem() +304
   System.Web.SessionState.SessionStateModule.BeginAcquireState(Object source, EventArgs e, AsyncCallback cb, Object extraData) +1076
   System.Web.AsyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +115
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +375

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.1008

我的 web.config 包含以下内容

提供者> 会话状态> ...

我可以在数据库中看到已经存在的条目:

表:my_aspnet_sessions

SessionId: 'jouwlxjdufet2fyvf4cwefn2'
ApplicationId: '1'
Created: '2013-08-22 08:29:34'
Expires: '2013-08-22 09:49:39'
LockDate: '2013-08-22 09:29:39'
LockId: '419'
Timeout: '20'
Locked: '0'
SessionItems: [lots of stuff]
Flats: '0'

我还可以看到 my_aspnet_sessioncleanup 表定期更新,表明会话清理正在运行(每 10 分钟一次)。

有人对从哪里开始调试有任何想法吗? 谢谢 大卫

【问题讨论】:

  • 您找到造成这种情况的原因了吗?我也有同样的问题...
  • 不,我没有发现,这是我使用 MySQL 连接器作为会话状态提供程序的完全障碍。我前往亚马逊,发现他们的 DynamoDB 会话状态提供程序非常有用。

标签: asp.net mysql iis session-state mysql-connector


【解决方案1】:

已修复!

我挖掘了 6.8.3 版本的代码。

在文件 SessionProvider.cs 中:通过始终使用 INSERT 查询,代码假设数据库中不存在会话键的任何行——这在创建会话时可以正常工作,但如果出现异常则抛出异常会话密钥被重复使用。

我使用同一个文件中已有的一些类似代码修复了它,并且不再出现异常。修改后的代码使用 REPLACE 查询而不是 INSERT。

我已在 MySQL 站点上附加了我的更新文件和相应错误的补丁(我的基本版本是 6.8.3)。您可以下载 6.8.3 源代码,并对其进行修补。如果您自己编译,您还必须在 AssemblyInfo.cs 中注释掉 AssemblyKeyName 属性(用于强程序集名称)。

希望 MySQL 人员将我的小修复推向普遍流通。

在这里查看我的笔记:

http://bugs.mysql.com/bug.php?id=70409

并且,在 MySql 更新正式版本之前的解决方法:

https://github.com/xavierjefferson/mysql-web-fixed

【讨论】:

    猜你喜欢
    • 2012-08-23
    • 2013-07-21
    • 2015-03-10
    • 2011-06-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-23
    • 1970-01-01
    相关资源
    最近更新 更多