【问题标题】:MysqlMembership Membership.ValidateUser Deadlock issue when under loadMysqlMembership Membership.ValidateUser 在负载下出现死锁问题
【发布时间】:2012-03-03 23:15:54
【问题描述】:

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

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

有什么想法吗?

谢谢, 弗里兹

【问题讨论】:

    标签: .net mysql wcf deadlock httpmodule


    【解决方案1】:

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

    如果向 ValidateUser 方法提供了不正确的密码,则 跟踪无效密码尝试的内部计数器递增 一个。这可能会导致用户被锁定并且无法登录 直到通过调用 UnlockUser 清除锁定状态 方法。如果提供了正确的密码并且用户不是 当前锁定,则跟踪无效的内部计数器 密码和密码回答尝试重置为零。更多 信息,请参阅 MaxInvalidPasswordAttempts 和 PasswordAttemptWindow 属性。

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

    由于您对所有请求都使用同一用户,因此您可能会遇到死锁。

    【讨论】:

    • 实际错误是在 lastActivityDate 发生死锁,但效果相同。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-08-28
    • 1970-01-01
    • 2014-06-06
    • 2011-03-28
    • 2012-04-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多