MysqlMembership Membership.ValidateUser加载时死锁问题

时间:2012-03-03 23:15:55

标签: .net mysql wcf deadlock httpmodule

我有一个带有自定义httpModule的WCF Web服务,我用它来对MysqlMembership进行UserName / Password身份验证。

public void Init(HttpApplication application)
    {
        application.AuthenticateRequest += new EventHandler(this.OnAuthenticateRequest);
        application.EndRequest += new EventHandler(this.OnEndRequest);
    }

    public void OnAuthenticateRequest(object source, EventArgs eventArgs)
    {
            ...
            ...

            if (Membership.ValidateUser(username, password))
            {

当我开始加载测试我的服务时,我遇到了一个令人困惑的问题。请求随机失败Membership.ValidateUser调用。我在负载测试器中为每个线程使用相同的用户名/登录名。这是错误:

  [MySqlException (0x80004005): Deadlock found when trying to get lock; try restarting transaction]
  MySql.Data.MySqlClient.MySqlStream.ReadPacket() +506
  MySql.Data.MySqlClient.NativeDriver.GetResult(Int32& affectedRow, Int32& insertedId) +450
  MySql.Data.MySqlClient.Driver.NextResult(Int32 statementId, Boolean force) +131
  MySql.Data.MySqlClient.MySqlDataReader.NextResult() +1216
  MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior) +2191
  MySql.Data.MySqlClient.MySqlCommand.ExecuteNonQuery() +27
  MySql.Web.Security.MySQLMembershipProvider.ValidateUser(String username, String password) +1092

  [ProviderException: An exception occurred. Please check the Event Log.]
  MySql.Web.Security.MySQLMembershipProvider.ValidateUser(String username, String password) +1481
  MyApplication.UserAuthenticator.UserNameAuthenticator.OnAuthenticateRequest(Object source, EventArgs eventArgs) in C:\Develop\MyProject\MyProject.UserAuthenticator\UserNameAuthenticator.cs:123
  System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +80
  System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)      +270

有什么想法吗?

谢谢, AFrieze

1 个答案:

答案 0 :(得分:0)

如果密码无效,验证用户会锁定该行以增加无效密码尝试次数:

  

如果为ValidateUser方法提供了错误的密码,则   跟踪无效密码尝试的内部计数器会递增   一个人。这可能导致用户被锁定而无法登录   打开,直到通过调用UnlockUser清除锁定状态   方法。如果提供了正确的密码而用户没有   目前锁定,然后跟踪无效的内部计数器   密码和密码应答尝试重置为零。更多   信息,请参阅MaxInvalidPasswordAttempts和   PasswordAttemptWindow属性。

http://msdn.microsoft.com/en-us/library/system.web.security.sqlmembershipprovider.validateuser.aspx

由于您对所有请求使用相同的用户,因此可能会出现死锁。