-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Description
Steps to reproduce the problem
There are two type of codes.
Type A:
void thread_func(Poco::Data::SessionPool *pool)
{
Poco::Data::Session ses(pool->get());
auto rs = new Poco::Data::RecordSet(ses, "select * from question");
//use rs to traverse
delete rs;
}
Type B:
Poco::Data::RecordSet* query(const std::string &str, Poco::Data::SessionPool *pool)
{
Poco::Data::Session ses(pool->get());
auto rs = new Poco::Data::RecordSet(ses, str);
return rs;
}
void thread_func(Poco::Data::SessionPool *pool)
{
auto rs = query("select * from question", pool);
//use rs to traverse
delete rs;
}
"Type A" is quite stable, but "Type B" is easy to crash in multithread environment.
I known it must has something to do with the scope of 'Session' object, but can any one tell me the primary cause of crash.
One of the crash backtrace is:
#0 mysql_prune_stmt_list (mysql=0x7f7e00032c30) at /home/emi/mysql-5.7.23/sql-common/client.c:5155
#1 end_server (mysql=mysql@entry=0x7f7e00032c30) at /home/emi/mysql-5.7.23/sql-common/client.c:1606
#2 0x00007f7e86195630 in cli_safe_read_with_ok (mysql=mysql@entry=0x7f7e00032c30, parse_ok=parse_ok@entry=0 '\000', is_data_packet=is_data_packet@entry=0x0) at /home/emi/mysql-5.7.23/sql-common/client.c:1071
#3 0x00007f7e8619576f in cli_safe_read (mysql=mysql@entry=0x7f7e00032c30, is_data_packet=is_data_packet@entry=0x0) at /home/emi/mysql-5.7.23/sql-common/client.c:1194
#4 0x00007f7e86190016 in cli_read_prepare_result (mysql=0x7f7e00032c30, stmt=0x7f7e2800b9a0) at /home/emi/mysql-5.7.23/libmysql/libmysql.c:1469
#5 0x00007f7e8619054f in mysql_stmt_prepare (stmt=0x7f7e2800b9a0, query=0x7f7e2800bfe8 "select * from question where id in (select question_id from ai.query_question_script where script_id='40')", length=106)
at /home/emi/mysql-5.7.23/libmysql/libmysql.c:1676
#6 0x00007f7e87d87952 in Poco::Data::MySQL::StatementExecutor::prepare (this=this@entry=0x7f7e2800b850, query="select * from question where id in (select question_id from ai.query_question_script where script_id='40')")
at /home/emi/zhangjin_install_poco/poco-1.9.0-all/Data/MySQL/src/StatementExecutor.cpp:56
#7 0x00007f7e87d8c329 in Poco::Data::MySQL::MySQLStatementImpl::compileImpl (this=0x7f7e2800b650) at /home/emi/zhangjin_install_poco/poco-1.9.0-all/Data/MySQL/src/MySQLStatementImpl.cpp:122
#8 0x00007f7e8806aacc in Poco::Data::StatementImpl::compile (this=this@entry=0x7f7e2800b650) at /home/emi/zhangjin_install_poco/poco-1.9.0-all/Data/src/StatementImpl.cpp:184
#9 0x00007f7e8806abed in Poco::Data::StatementImpl::execute (this=0x7f7e2800b650, reset=@0x7f7dd7fcec8c: true) at /home/emi/zhangjin_install_poco/poco-1.9.0-all/Data/src/StatementImpl.cpp:86
#10 0x00007f7e8813cca8 in Poco::Data::Statement::execute (this=0x7f7dd7fced10, reset=true) at /home/emi/zhangjin_install_poco/poco-1.9.0-all/Data/src/Statement.cpp:105
#11 0x00007f7e8813be86 in Poco::Data::Statement::operator, (this=this@entry=0x7f7dd7fced10, manip=manip@entry=0x7f7e880e2f30 Poco::Data::Keywords::now(Poco::Data::Statement&))
at /home/emi/zhangjin_install_poco/poco-1.9.0-all/Data/src/Statement.cpp:183
#12 0x00007f7e880e4f2c in Poco::Data::RecordSet::RecordSet (this=0x7f7e2800df10, rSession=..., query="select * from question where id in (select question_id from ai.query_question_script where script_id='40')",
pRowFormatter=...) at /home/emi/zhangjin_install_poco/poco-1.9.0-all/Data/src/RecordSet.cpp:51
#13 0x00000000004018ab in query(std::string const&, Poco::Data::SessionPool*) ()
#14 0x0000000000401957 in thread_func(Poco::Data::SessionPool*) ()
#15 0x00000000004042a2 in void std::_Bind_simple<void ((Poco::Data::SessionPool))(Poco::Data::SessionPool*)>::_M_invoke<0ul>(std::_Index_tuple<0ul>) ()
#16 0x00000000004041ad in std::_Bind_simple<void ((Poco::Data::SessionPool))(Poco::Data::SessionPool*)>::operator()() ()
#17 0x0000000000404146 in std::thread::_Impl<std::_Bind_simple<void ((Poco::Data::SessionPool))(Poco::Data::SessionPool*)> >::_M_run() ()
#18 0x00007f7e8773a070 in ?? () from /lib64/libstdc++.so.6
#19 0x00007f7e86b95e25 in start_thread () from /lib64/libpthread.so.0
#20 0x00007f7e86ea234d in clone () from /lib64/libc.so.6
POCO version
v 1.9
Operating system and version
centos 7