对过期会话MySQL的会话状态提供程序崩溃 [英] MySQL Session state provider crashes on expired sessions

查看:272
本文介绍了对过期会话MySQL的会话状态提供程序崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a site running in IIS 7.5 ASP.NET 4 using MySQL Connector 6.7.4, I am trying to set it up to store session state in my database. It works fine to start with (I can store the state). But when I leave my browser open for a long time and then tries to refresh a page I get the following error:

对于重复条目'jouwlxjdufet2fyvf4cwefn2-1关键主要

Duplicate entry 'jouwlxjdufet2fyvf4cwefn2-1' for key 'PRIMARY'

说明:当前Web请求的执行过程中发生未处理的异常。请检查堆栈跟踪有关该错误的详细信息以及它起源于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 web.config contains the following


<system.web>
  <sessionState mode="Custom" cookieless="false" regenerateExpiredSessionId="false" customProvider="MySqlSessionStateProvider" timeout="20">
    <providers>
      <add name="MySqlSessionStateProvider" type="MySql.Web.SessionState.MySqlSessionStateStore, MySql.Web, Version=6.7.4.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" applicationName="/skygdadmin" description="" connectionStringName="MySqlServer" writeExceptionsToEventLog="False" autogenerateschema="True" enableExpireCallback="True" />
    </providers>
  </sessionState>
...

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

I can see in the database the already existing entry:

表:my_aspnet_sessions

Table: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分钟)。

Also I can see that the my_aspnet_sessioncleanup table is updated regularly indicating that session cleanup is running (every 10 min).

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

Does anyone have any ideas on where to start the debugging? Thanks David

推荐答案

修正了吧!

我在code挖了6.8.3版本。

I dug through the code for version 6.8.3.

在文件SessionProvider.cs:通过始终使用INSERT查询时,code是假设没有排为会话密钥已经存在于数据库 - 它工作正常创建会话时,但抛出如果会话密钥被重复使用异常。

In the file SessionProvider.cs: By always using an INSERT query, the code is assuming that no row for the session key already exists in the database -- which works fine for when the session is created, but throws an exception if the session key gets re-used.

我和一些类似code已经在同一个文件内固定它,我不再让除外。修改后的code使用一个REPLACE查询,而不是INSERT。

I fixed it with some similar code already within the same file, and I'm no longer getting the exception. The modified code uses a REPLACE query instead of INSERT.

我附上我更新的文件和关于MySQL网站的相应缺陷的补丁(我的基本版本是6.8.3)。您也可以下载6.8.3源代码,并修补它。您还可以在AssemblyInfo.cs中注释掉AssemblyKeyName属性(强集名称),如果你自己编译。

I've attached my updated file and a patch on a corresponding bug on the MySQL site (my base version is 6.8.3). You can download the 6.8.3 source, and patch it. You'll also have to comment out the AssemblyKeyName attribute (for strong assembly name) in AssemblyInfo.cs if you compile it yourself.

希望MySQL的人会推我的小修复伸到一般循环。

Hopefully the MySQL folks will push my little fix out into general circulation.

请参阅我的笔记这里:

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

和,变通方法,直到更新的MySQL官方发布:

And, a workaround until MySql updates the official release:

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

这篇关于对过期会话MySQL的会话状态提供程序崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆