.net - MysqlMembership Membership.ValidateUser 负载下出现死锁问题

标签 .net mysql wcf deadlock httpmodule

我有一个带有自定义 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

有什么想法吗?

谢谢, 弗里兹

最佳答案

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

If an incorrect password is supplied to the ValidateUser method, the internal counter that tracks invalid password attempts is incremented by one. This can result in the user being locked out and unable to log on until the lock status is cleared by a call to the UnlockUser method. If the correct password is supplied and the user is not currently locked out, then the internal counters that track invalid password and password-answer attempts are reset to zero. For more information, see the MaxInvalidPasswordAttempts and PasswordAttemptWindow properties.

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

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

关于.net - MysqlMembership Membership.ValidateUser 负载下出现死锁问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9550711/

相关文章:

.net - 如何从服务实现内部读取服务端点名称

.net - Entity Framework SaveChanges 不更新数据库

c# - PerfView:分析应用程序的性能,包括数据库调用

c# - 使用对象初始化时如何获取父类(即初始化当前类的类)的实例?

mysql - Rails 3 在 2 个表之间进行连接

php - 从表中删除列

python - 使用没有模型的 django

c# - Tridion 2011 核心服务 : Unable to connect in a SSO environment

c# - CrystalReport 和/或 Visual studio 2010 的情况很奇怪我不知道 .Net Framework

wcf - 使用 DataContractAttribute 和 ISerializable