Closed kylindai closed 1 year ago
Hi @kylindai,
This looks like a race condition on a connection
object. By design, connections are not thread-safe, and impose the condition on having a single outstanding network operation at a time.
Some questions to help you move forward:
connection
? Are you using boost::asio::strand
or similar?Regards, Ruben.
Thanks for getting your reply so soon.
Yes, it's an usual connection pool implement, pre-creating a group of connections in a vector, and each conn has it's own io_context, and pre-connect the mysql server, when the operation finished, not close the connection really.
Is this a wrong usage? Any idea for creating connection pool of using this library? Thanks a lot~
Hi @kylindai,
The pattern you describe is a valid usage of the library, as long as you can guarantee that only one operation is outstanding for a given connection at a single time. I've got the feeling that your code is failing to guarantee this condition.
If you could somehow share me your connection pool code, I can assist you to find whether this is the case or not.
Edit: are you using sync or async functions?
Regards, Ruben.
Hi @anarthal
Thanks for your reply, I have got my mistake, it is a bug in my codes:
T& get_conn() {
std::lockguard
return conn_holder->get(); // here, many threads could get the same conn that not been released
}
bool release(T& conn) {
std::lockguard
The library is excellent !!! This issue could be closed, thanks.
Glad you could find it. I'm closing this issue now. If you have any further questions, please ask.
When I update my table in multi-thread way, I always get the following error msgs:
_mysql error_code = End of file [asio.misc:2] mysql errorcode = Mismatched sequence numbers [mysql.client:5]
And I have closed the statement by invoke conn.close_statement() after each calling conn.execute(stmt.bind(...), dig, ec);
Some advice could give me? Thanks a lot~