Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using Mysql 5.5.44-0ubuntu0.12.04.1 get error #66

Closed
ajdwfnhaps opened this issue Nov 30, 2017 · 15 comments
Closed

Using Mysql 5.5.44-0ubuntu0.12.04.1 get error #66

ajdwfnhaps opened this issue Nov 30, 2017 · 15 comments

Comments

@ajdwfnhaps
Copy link

CAP数据使用Mysql版本为5.5.44-0ubuntu0.12.04.1 时,我测试只发送1条MQ消息,但接收到33条一模一样的消息,详情请看以下载图:

1.发出的:
image

2.接收的:
image

Id都一样,内容也一样,接收到了33条消息,订阅方法触发了33次,好奇怪的现象,想请教一下大概是什么问题呢?

PS:当我数据库切换成Mysql 5.7后就没有这种问题了,是否也是mysql语法的问题导致?貌似是不断的重试机制造成的,cap.queue表里会出现重复的MessageId一样的记录在运行……

@yang-xiaodong
Copy link
Member

把你项目上传到github我看一下配置和结构

@ajdwfnhaps
Copy link
Author

@yuleyule66 请查看

@ajdwfnhaps
Copy link
Author

PS: 同时启动了这两个项目

 "MultiProjectConfigurations": {
    "Quartz + CAP": {
      "Projects": {
        "AAM.Quartz.Web": {},
        "AAM.Finance.CAP": {}
      }
    }

  }

@yang-xiaodong
Copy link
Member

无用代码太多了,你可以把没用代码都删除掉,而且我没有数据库也运行不起来,建议能够使用最简单的代码能够把你的问题复现出来。

image

这个地方是一个长的调用链吗? 是消费了之后又要发送到其他消息进行消费? 为什么你的publlish方法没有在事务里面呢?

@ajdwfnhaps
Copy link
Author

好的,我删除了一些没用的代码,去掉了数据库,除了两个cap1 cap2的库,
现在换了cap的两个库的连接串和MQ的配置就可以跑起来的了。

您截图的地方,是长的调用链来的,一批MQ消息消费完后,跟着一个eof结束的标识消息,然后触发下一步汇总的处理,我eof的publish没有包在事务里,因为它是消费结束的标识,没有其它数据库操作事务。

我调整完这些代码后,还使用了Mysql 5.5.44-0ubuntu0.12.04.1测试了一下,问题仍旧,希望能够找到原因,使CAP能更完善,非常感谢

@ajdwfnhaps
Copy link
Author

@yang-xiaodong
Copy link
Member

Hi @ajdwfnhaps ~
我已经在 2.1.2-preview-28879945 版本修复了这个bug,谢谢你的反馈。

如果还有其他问题,可以 reopen 此 issue。

@ajdwfnhaps
Copy link
Author

太好了,非常感谢,我这边已更新测试过了,现在没问题了

@ajdwfnhaps
Copy link
Author

BTW,能否用我这个示例项目修改为异步发送MQ消息测试一下(PublishAsync),我这边测试异步发送就有可能报以下这个错误:

[2017-12-01 15:39:12.3830] [] [ERROR] [AAM.Quartz.Tasks.Finance.AccountPeriodJob]: Job执行中发生错误,ErrMsg:There is already an open DataReader associated with this Connection which must be closed first. System.InvalidOperationException: There is already an open DataReader associated with this Connection which must be closed first. at MySqlConnector.Core.ServerSession.StartQuerying(MySqlCommand command) in C:\projects\mysqlconnector\src\MySqlConnector\Core\ServerSession.cs:line 115 at MySqlConnector.Core.TextCommandExecutor.<ExecuteReaderAsync>d__3.MoveNext() in C:\projects\mysqlconnector\src\MySqlConnector\Core\TextCommandExecutor.cs:line 66 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at MySqlConnector.Core.TextCommandExecutor.<ExecuteNonQueryAsync>d__1.MoveNext() in C:\projects\mysqlconnector\src\MySqlConnector\Core\TextCommandExecutor.cs:line 25 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at MySql.Data.MySqlClient.MySqlTransaction.<CommitAsync>d__2.MoveNext() in C:\projects\mysqlconnector\src\MySqlConnector\MySql.Data.MySqlClient\MySqlTransaction.cs:line 27 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at MySql.Data.MySqlClient.MySqlTransaction.Commit() in C:\projects\mysqlconnector\src\MySqlConnector\MySql.Data.MySqlClient\MySqlTransaction.cs:line 13 at DotNetCore.CAP.Abstractions.CapPublisherBase.ClosedCap() in D:\Work\aimei_finance\trunk\code\aimei_finance\CAP\DotNetCore.CAP\Abstractions\CapPublisherBase.cs:line 162 at DotNetCore.CAP.Abstractions.CapPublisherBase.<PublishWithTransAsync>d__35.MoveNext() in D:\Work\aimei_finance\trunk\code\aimei_finance\CAP\DotNetCore.CAP\Abstractions\CapPublisherBase.cs:line 137 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at AAM.Quartz.Domain.Service.Finance.AccountPeriodService.<Execute>d__7.MoveNext() in D:\Work\aimei_finance\trunk\code\aimei_finance\Quartz\AAM.Quartz.Domain.Service\Finance\Implementation\AccountPeriodService.cs:line 70 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at AAM.Quartz.Tasks.Finance.AccountPeriodJob.<Invoke>d__3.MoveNext() in D:\Work\aimei_finance\trunk\code\aimei_finance\Quartz\AAM.Quartz.Task\Finance\AccountPeriodJob.cs:line 32 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at AAM.Quartz.Tasks.JobBase.<Execute>d__3.MoveNext() in D:\Work\aimei_finance\trunk\code\aimei_finance\Quartz\AAM.Quartz.Task\JobBase.cs:line 40

@yang-xiaodong
Copy link
Member

yang-xiaodong commented Dec 1, 2017

你的项目我已经运行起来了,怎么样发消息呢? @ajdwfnhaps

我需要运行 tables_mysql_innodb.sql 生成表吗?

你还需要补充说明一下你这个项目的运行原理

@ajdwfnhaps
Copy link
Author

@yuleyule66 不需要运行sql的,您跑起来后有这个Job吗,有就手动执行一下就可以发消息的了

image

如果没有这个Job,需要替换一下quartz.db这个Sqlite数据库,位置在项目AAM.Quartz.Web\Persistence\SQLite

quartz.zip

@yang-xiaodong
Copy link
Member

启动 AAM.Quartz.Web
访问 :http://localhost:10931/
出现下面这个错误:

{"Success":-1,"Title":"全局异常处理中间件返回信息","Msg":"错误代码:200,提示信息:Failed to obtain DB connection from data source 'default': Microsoft.Data.Sqlite.SqliteException (0x80004005): SQLite Error 14: 'unable to open database file'.\r\n   at Microsoft.Data.Sqlite.SqliteException.ThrowExceptionForRC(Int32 rc, sqlite3 db)\r\n   at Microsoft.Data.Sqlite.SqliteConnection.Open()\r\n   at Quartz.Impl.AdoJobStore.JobStoreSupport.GetConnection()"}

@ajdwfnhaps
Copy link
Author

不好意思,还有一步,AAM.Quartz.Web 的appsetting.json 要配置一下quartz.db的连接串信息:

image

@yang-xiaodong
Copy link
Member

这个问题是由于并发冲突导致。

因为连接池的问题,不同线程获取到了相同的连接,mysql不支持同一个连接一边DataReader读,一边进行Execute。

默认情况下,在PublishAsync内部会开启事务,当CAP检测的外围事务时,会使用外围事务。

手动开启事务,会大大降低这种概率发生的可能性。

using (var trans = await _dbContext.Database.BeginTransactionAsync())
{
    for (int i = 0; i < 1000; i++)
    {
        await _capBus.PublishAsync("sample.test.testsend", DateTime.Now);
    }
    trans.Commit();
}

@ajdwfnhaps
Copy link
Author

好的,谢谢,我稍后就试吓

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants