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

GetNextPublishedMessageToBeEnqueuedAsync Function Error #83

Closed
BennetWang opened this issue Jan 25, 2018 · 6 comments

Comments

@BennetWang
Copy link

commented Jan 25, 2018

Before we exceute the 'connection.Execute("SELECT LAST_INSERT_ID(0)");',We must manual open the dbconnection 'connection.Open();'
That is because the LAST_INSERT_ID function is based on the connection and the Execute function of the dapper is closed when the connection is closed before executed.so,we cannot guarantee that we get the same connection.

@yang-xiaodong

This comment has been minimized.

Copy link
Member

commented Jan 25, 2018

I don't quite understand what you mean, why you want to exceute the connection.Execute("SELECT LAST_INSERT_ID(0)") , and what's the error of GetNextPublishedMessageToBeEnqueuedAsync method ?

@BennetWang

This comment has been minimized.

Copy link
Author

commented Jan 25, 2018

我说中文吧。就是LAST_INSERT_ID是连接级别的,那么你如何保证GetNextPublishedMessageToBeEnqueuedAsync这个方法执行两遍不会取到同一条的数据?首先.NET内置了一个连接池,每次open去线程池取连接。如果两次执行更新查询都是同一个连接,但是执行置空LAST_INSERT_ID是另外一个连接,那是不是就会出现重复数据了。。我今天测试了很多次,都出现了这个问题。同一个消息,在queue这张表中生成多条数据。

@BennetWang

This comment has been minimized.

Copy link
Author

commented Jan 25, 2018

Dapper的方法是每次执行完执行会判断原先的连接是否开启,如果是关闭,那么它就会帮你关闭掉。所以,
connection.Execute("SELECT LAST_INSERT_ID(0)");
await connection.QueryFirstOrDefaultAsync(sql);
这两句代码不一定是同一个连接。所以我在前面加了 connection.Open();

@BennetWang

This comment has been minimized.

Copy link
Author

commented Jan 25, 2018

我采用的是MySql,你看一下MySqlStorageConnection这个类。这个是其中的一个方法。

@yang-xiaodong yang-xiaodong added the bug label Jan 26, 2018

@yang-xiaodong

This comment has been minimized.

Copy link
Member

commented Jan 26, 2018

Yes, you are right.

I looked at the Dapper source code, if the connection is opened by Dapper then Dapper will be close the connection after Execute. This may result in the execution of LAST_INSERT_ID not the same connection as executing SQL statements.

I will fix this issue later, thanks for your report.

yang-xiaodong added a commit that referenced this issue Jan 26, 2018

@yang-xiaodong yang-xiaodong added the fixed label Jan 26, 2018

@yang-xiaodong

This comment has been minimized.

Copy link
Member

commented Jan 26, 2018

version 2.1.4-preview-33704197 fixed this bug.

@BennetWang BennetWang closed this Feb 7, 2018

yang-xiaodong added a commit that referenced this issue Mar 16, 2018
Release version 2.1.4 (#97)
* Fixed the connection bug of getting message from table. #83

* update version to 2.1.4

* remove `TableNamePrefix` option from `MySqlOptions` to `EFOptions`.  #84

* fixed entityframework rename table name prefix bug.  #84

* fixed sql server scripts bug of create table scheme. #85

* fixed entityframework rename table name prefix bug. #84

* modify error message of logger write

* Fixed bug of the FailedRetryCount does not increase when raised SubscriberNotFoundException. #90

* Fixed thread safety issue about KafkaOptions. #89

* upgrade nuget package
yang-xiaodong added a commit that referenced this issue Aug 21, 2018
Release version 2.1.4 (#97)
* Fixed the connection bug of getting message from table. #83

* update version to 2.1.4

* remove `TableNamePrefix` option from `MySqlOptions` to `EFOptions`.  #84

* fixed entityframework rename table name prefix bug.  #84

* fixed sql server scripts bug of create table scheme. #85

* fixed entityframework rename table name prefix bug. #84

* modify error message of logger write

* Fixed bug of the FailedRetryCount does not increase when raised SubscriberNotFoundException. #90

* Fixed thread safety issue about KafkaOptions. #89

* upgrade nuget package
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.