I have a multithread application which accesses a DB from multiple thread, and randomically I fall in this error (not the same query)...
__GI___libc_free (mem=0x7fff00042660) at /build/glibc-vjB4T1/glibc-2.28/malloc/malloc.c:3093
QList<_RData>::node_destruct (this=0x7fffebffce08, from=0x7fffe4037fc0, to=0x7fffe4037fd8) at /usr/include/x86_64-linux-gnu/qt5/QtCore/qlist.h:494
QList<_RData>::dealloc (this=0x7fffebffce08, data=0x7fffe4037fb0) at /usr/include/x86_64-linux-gnu/qt5/QtCore/qlist.h:865
QList<_RData>::~QList (this=0x7fffebffce08) at /usr/include/x86_64-linux-gnu/qt5/QtCore/qlist.h:827
QList<_RData>::operator= (this=0x55555565cd68, other=#0x7fffebffd880: {<QListSpecialMethods<_RoomData>> = {<No data fields>}, {p = {static shared_null = {ref = {atomic = {_q_value = {<std::__atomic_base<int>> = {static _S_alignment = 4, _M_i = -1}, <No data fields>}}}, alloc = 0, begin = 0, end = 0, array = {0x0}}, d = 0x7ffff6ff76c0 <QListData::shared_null>}, d = 0x7ffff6ff76c0 <QListData::shared_null>}}) at /usr/include/x86_64-linux-gnu/qt5/QtCore/qlist.h:159
AMProcess::doActionAM (this=0x55555565cc30) at /smart/software/AudioIO/AMProcess.cpp:453
QtPrivate::FunctorCall<QtPrivate::IndexesList<>, QtPrivate::List<>, void, void (AMProcess::*)()>::call(void (AMProcess::*)(), AMProcess*, void**) (f=(void (AMProcess::*)(AMProcess * const)) 0x5555555b943c <AMProcess::doActionAM()>, o=0x55555565cc30, arg=0x7fffebffee40) at /usr/include/x86_64-linux-gnu/qt5/QtCore/qobjectdefs_impl.h:134
QtPrivate::FunctionPointer<void (AMProcess::*)()>::call<QtPrivate::List<>, void>(void (AMProcess::*)(), AMProcess*, void**) (f=(void (AMProcess::*)(AMProcess * const)) 0x5555555b943c <AMProcess::doActionAM()>, o=0x55555565cc30, arg=0x7fffebffee40) at /usr/include/x86_64-linux-gnu/qt5/QtCore/qobjectdefs_impl.h:167
QtPrivate::QSlotObject<void (AMProcess::*)(), QtPrivate::List<>, void>::impl(int, QtPrivate::QSlotObjectBase*, QObject*, void**, bool*) (which=1, this_=0x555555661cf0, r=0x55555565cc30, a=0x7fffebffee40, ret=0x0) at /usr/include/x86_64-linux-gnu/qt5/QtCore/qobjectdefs_impl.h:396
QMetaObject::activate(QObject*, int, int, void**) () at null:
QThread::started(QThread::QPrivateSignal) () at null:
?? () at null:
start_thread (arg=<optimized out>) at /build/glibc-vjB4T1/glibc-2.28/nptl/pthread_create.c:486
clone () at /build/glibc-vjB4T1/glibc-2.28/misc/../sysdeps/unix/sysv/linux/x86_64/clone.S:95
This is some snippets of my code
rData = DBRManager::ReadRData("R", m_connName);
if (rData.size() > 0) {
}
...and this is the query
QList<_RData> DBRManager::ReadRData(QString tbName, QString dbName)
{
QList<_RData> records;
QSqlQuery query(QSqlDatabase::database(dbName));
query.setForwardOnly(true);
query.exec("DSQLITE_THREADSAFE=2");
query.exec("SELECT * FROM " + tbName);
while (query.next()) {
_RData data;
data.id = query.value("id").toInt();
data.type = query.value("type").toInt();
records.append(data);
}
query.finish();
return records;
}
Related
Some pieces of my code crash randomly when call push_back or erase on std::list, the code is in a long time runing service . I removed the unimportant part and just keep the most relevant.
std::list<RxCCPReport> pendingSync;
size_t AnchorConnection::HandleCCPTxReport(const char *rxBytes, size_t length) {
if (!pendingSync.empty())
{
std::list<RxCCPReport>::iterator iter = pendingSync.begin();
while (iter != pendingSync.end())
{
if (condition1)
{
iter = pendingSync.erase(iter);
}
else
{
if (condition2)
{
++iter;
}
else if (condition3)
{
++iter;
}
else
{
iter = pendingSync.erase(iter);
}
}
}
}
return length; }
size_t AnchorConnection::HandleCCPRxReport(const char *rxBytes, size_t length) {
RxCCPReport rxCCP;
rxCCP.anc = anc;
rxCCP.rxTime = ccpRxTime;
rxCCP.seqNum = pCsMsg->seqNum;
pendingSync.push_back(rxCCP);
return length;
}
The two function runs on the same thread; code will crash at pendingSync.erase(iter) or pendingSync.push_back(rxCCP) sometimes, about 1 time a week.
the backtrace:
crashed at erase
#0 std::__detail::_List_node_base::_M_unhook (this=0x7fffcc024040) at ../../../../../libstdc++-v3/src/c++98/list.cc:142
__next_node = 0x0
__prev_node = 0x7fffcc024040
#1 0x00000000004db14a in std::list<RxCCPReport, std::allocator<RxCCPReport> >::_M_erase (this=0x7fffdc011970, __position=...) at /usr/include/c++/4.8.2/bits/stl_list.h:1570
__n = 0x7fffe5ffad80
#2 0x00000000004daddb in std::list<RxCCPReport, std::allocator<RxCCPReport> >::erase (this=0x7fffdc011970, __position=...) at /usr/include/c++/4.8.2/bits/list.tcc:112
__ret = <error reading variable __ret (Cannot access memory at address 0x10)>
#3 0x00000000004e3d8b in AnchorConnection::HandleCCPTxReport (this=0x7fffdc009240, rxBytes=0x7fffc4022abb "0rl\206%M/\004\205O\263\002\216\356\003\002f", length=12)
at LE/Network/rtls_anchor_conn.cpp:731
rxCCP = {rxTime = 3.1943677384753104, seqNum = 114 'r', anc = }
cSeqRxCCP = 114 'r'
cs = 0x7fffdc016430
ccpTx = 203157767788
ccpTxTime = 3.1794272052158457
pCsMsg = 0x7fffc4022abb
cSeqTxCCP = 114 'r'
crashed at push_back another time
> #0 0x00007ffff6dff387 in __GI_raise (sig=sig#entry=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:55
resultvar = 0
pid = 5068
selftid = 5418
#1 0x00007ffff6e00a78 in __GI_abort () at abort.c:90
save_stage = 2
act = {__sigaction_handler = {sa_handler = 0x7ffff6ddb76d, sa_sigaction = 0x7ffff6ddb76d}, sa_mask = {__val = {5, 140737336646961, 3, 140737043728478, 2,
140737336643303, 1, 140737336652017, 3, 140737043728452, 12, 140737336652021, 2, 140737043729264, 140737043729264, 140737043731024}}, sa_flags = 16,
sa_restorer = 0x7fffe57f8d70}
sigs = {__val = {32, 0 <repeats 15 times>}}
#2 0x00007ffff6e41ed7 in __libc_message (do_abort=do_abort#entry=2, fmt=fmt#entry=0x7ffff6f54350 "*** Error in `%s': %s: 0x%s ***\n")
at ../sysdeps/unix/sysv/linux/libc_fatal.c:196
ap = {{gp_offset = 40, fp_offset = 48, overflow_arg_area = 0x7fffe57f9260, reg_save_area = 0x7fffe57f9170}}
ap_copy = {{gp_offset = 16, fp_offset = 48, overflow_arg_area = 0x7fffe57f9260, reg_save_area = 0x7fffe57f9170}}
fd = 26
on_2 = <optimized out>
list = <optimized out>
nlist = <optimized out>
cp = <optimized out>
written = <optimized out>
#3 0x00007ffff6e483e4 in malloc_printerr (action=<optimized out>, str=0x7ffff6f54548 "malloc(): memory corruption (fast)", ptr=<optimized out>, ar_ptr=<optimized out>)
at malloc.c:4967
buf = "00007fffd8001570"
cp = <optimized out>
ar_ptr = <optimized out>
ptr = <optimized out>
str = 0x7ffff6f54548 "malloc(): memory corruption (fast)"
action = <optimized out>
#4 0x00007ffff6e4bb20 in _int_malloc (av=av#entry=0x7fffd0000020, bytes=bytes#entry=40) at malloc.c:3383
p = 0x7fffd8001560
fb = <optimized out>
pp = <optimized out>
nb = 48
idx = <optimized out>
bin = <optimized out>
victim = 0x7fffd8001560
size = <optimized out>
victim_index = <optimized out>
remainder = <optimized out>
remainder_size = <optimized out>
block = <optimized out>
bit = <optimized out>
map = <optimized out>
fwd = <optimized out>
bck = <optimized out>
errstr = <optimized out>
#5 0x00007ffff6e4e6fc in __GI___libc_malloc (bytes=40) at malloc.c:2905
ar_ptr = 0x7fffd0000020
victim = <optimized out>
hook = <optimized out>
#6 0x00007ffff7929ecd in operator new (sz=40) at ../../../../libstdc++-v3/libsupc++/new_op.cc:51
p = <optimized out>
#7 0x00000000004dc6f8 in __gnu_cxx::new_allocator<std::_List_node<RxCCPReport> >::allocate (this=0x7fffdc011930, __n=1) at /usr/include/c++/4.8.2/ext/new_allocator.h:104
No locals.
#8 0x00000000004dc006 in std::_List_base<RxCCPReport, std::allocator<RxCCPReport> >::_M_get_node (this=0x7fffdc011930) at /usr/include/c++/4.8.2/bits/stl_list.h:334
No locals.
#9 0x00000000004db699 in std::list<RxCCPReport, std::allocator<RxCCPReport> >::_M_create_node<RxCCPReport const&> (this=0x7fffdc011930)
at /usr/include/c++/4.8.2/bits/stl_list.h:502
__p = 0x0
#10 0x00000000004db1c2 in std::list<RxCCPReport, std::allocator<RxCCPReport> >::_M_insert<RxCCPReport const&> (this=0x7fffdc011930, __position=...)
at /usr/include/c++/4.8.2/bits/stl_list.h:1561
__tmp = 0x0
#11 0x00000000004dae68 in std::list<RxCCPReport, std::allocator<RxCCPReport> >::push_back (this=0x7fffdc011930, __x=...) at /usr/include/c++/4.8.2/bits/stl_list.h:1016
No locals.
#12 0x00000000004e475b in AnchorConnection::HandleCCPRxReport (this=0x7fffdc01be90, rxBytes=0x7fffd004d7fb "1{\212\211D\021\006\061+\b\250\256i\227#ԺF(ú\002\005\003o\200#",
length=88) at LE/Network/rtls_anchor_conn.cpp:936
rxCCP = {rxTime = 4.3416058279497198, seqNum = 123 '{', anc = 0x7fffdc016320}
prevSeqNum = 122 'z'
master = 0x7fffdc0101a0
cs = 0x7fffdc016450
masterID = 588618078431250826
logNum = 45794088
pCsMsg = 0x7fffe57f9500
ccpRx = 277418192552
ccpRxTime = 4.3416058279497198
txTime = "0000000000\000\334\377\177\000\000\177\236", <incomplete sequence \345>
temp = "\000\000\000\000"
diagMsg2 = "0F000005036F8040001000000412C8A607120000086000BC07390AD806130000040000FC0114000005F9FF0700731500000EA8AE699740D4BA740800EC69974025000010A604C3FB4C07A3F7520743FE260538072E100002EF022700280491FE1F6D2E100"...
csmsg = {type = 49 '1', seqNum = 123 '{', masterID = "\212\211D\021\006\061+\b", csRxTime = "\250\256i\227#", {firstPath16 = 47828, firstPath = "Ժ"},
extLen = 70 'F', {
ext = "(ú\002\005\003o\200#\000\022Ȧ\a`\000\274\a9\n\330\006\000\000\374\001\371\377\a\000s\250\256i\227#Ժt\b\000\354i\227#\000\246\004\303\373L\a\243\367R\aC\376&\005\070\a\357\002\221\376\037m?\021", {{logNum32 = 45794088, logNum = "(ú\002"},
diagnostics = "\005\003o\200#\000\022Ȧ\a`\000\274\a9\n\330\006\000\000\374\001\371\377\a\000s\250\256i\227#Ժt\b\000\354i\227#\000\246\004\303\373L\a\243\367R\aC\376&\005\070\a\357\002\221\376\037m?\021"}}}
FP = 747
rxTime = "409769AEA8\000\345\377\177\000\000Н", <incomplete sequence \345>
I was nearly mad, any suggestion appreciated
Code that receive data over socket is as follows:
#define FRAME_HEADER_LEN (6)
#define FRAME_DATA_IDX (3)
virtual void Run()
{
unsigned int length = 0;
std::string rxBytes;
bool msgProcess;
uint8_t fcode;
unsigned int flen = 0;
while (shutdown_select_anc(socket) != -1)
{
int count = socket->ReceiveData();
if (count <= 0) // Something failed. Socket is probably closed.
{
break;
}
length += count;
rxBytes.append(socket->buf_, count);
/*
* the data coming from the anchor is framed:
*<STX><LENlsb><LENmsb><DATA:<FC><XX>.....><CRClsb><CRCmsb><ETX>
* STX = 0x2
* LEN is the length of data message(16 bits)
* CRC is the 16 - bit CRC of the data bytes
* ETX = 0x3
* FC = is the function code (API code)
*/
if (length <= FRAME_HEADER_LEN) //minimum length is 7 bytes (header + 1 byte function code)
{
continue;
}
do {
msgProcess = false;
crc_err_t pckt_crc = CRC_ERROR;
//search through the received data to find the start of frame
while (length > FRAME_HEADER_LEN)
{
if ((rxBytes.c_str())[0] == 0x2) //this is the start - check if length and end match
{
uint8_t hi = (rxBytes.c_str())[2];
uint8_t lo = (rxBytes.c_str())[1];
flen = lo + ((uint16_t)hi << 8);
if ((flen + FRAME_HEADER_LEN) > length) //we don't have all the frame yet
{
break;
}
if ((rxBytes.c_str())[flen + 5] == 0x3) //end of frame present
{
//received whole frame: check frame checksum here
pckt_crc = check_crc16((uint8_t *)&(rxBytes.c_str())[3], (flen + 2));
break;
}
else //no end of frame in the expected place - start byte was not real start
{
rxBytes.erase(0, 1);
length -= 1;
}
}
else //remove the byte and check if next is a start of frame
{
rxBytes.erase(0, 1);
length -= 1;
}
}
//check if we have a frame
if (((flen + FRAME_HEADER_LEN) > length) || (length <= FRAME_HEADER_LEN))
{
break;
}
if (pckt_crc != CRC_OKAY)
{
//frame packet fully received but it's CRC bad
DBG_PRINTF(DBG_DEFAULT, "ACHTUNG ACHTUNG : incompatible software without CRC or network CRC error\n");
//let incompatible software proceed at the moment
}
fcode = (rxBytes.c_str())[FRAME_DATA_IDX]; //get function code
typename std::map<uint8_t, std::pair<size_t, handler> >::iterator it = handlers.find(fcode);
if (it != handlers.end()) //we have found a handler for this function code
{
if (flen >= it->second.first)
{
handler f = it->second.second;
size_t n = (static_cast<Child*>(this)->*f)(&((rxBytes.c_str())[FRAME_DATA_IDX]), flen );
if (n > 0)
{
msgProcess = true;
rxBytes.erase(0, n + FRAME_HEADER_LEN);
length -= (unsigned int)(n + FRAME_HEADER_LEN);
}
else
{
//Unexpected Message
rxBytes.clear();
length = 0;
}
}
}
else
{
rxBytes.clear();
length = 0;
}
} while((length > 0) && msgProcess);
}
socket->Close();
}
In the push_back case you have
str = 0x7ffff6f54548 "malloc(): memory corruption (fast)"
Suggests that you have an memory corruption elsewhere, most likely shortly before calling HandleCCPRxReport.
I am trying to write a wrapper for onnxruntime.
The model receives one tensor as an input and one tensor as an output.
During session->Run, a segmentation error occurs inside the onnxruntime library. Both downloaded library and built from source throw the same error.
Here is error:
Thread 1 "app" received signal SIGSEGV, Segmentation fault.
0x00007ffff6b16eb1 in onnxruntime::logging::ISink::Send (this=0x5555559154c0, timestamp=..., logger_id="", message=...) at /home/listray/Work/Libs/onnxruntime/include/onnxruntime/core/common/logging/isink.h:23
23 SendImpl(timestamp, logger_id, message);
Here is bt:
#0 0x00007ffff6b16eb1 in onnxruntime::logging::ISink::Send (this=0x5555559154c0, timestamp=..., logger_id="", message=...)
at /home/listray/Work/Libs/onnxruntime/include/onnxruntime/core/common/logging/isink.h:23
#1 0x00007ffff6b174b8 in onnxruntime::logging::LoggingManager::Log (this=0x55555576cbb0, logger_id="", message=...) at /home/listray/Work/Libs/onnxruntime/onnxruntime/core/common/logging/logging.cc:153
#2 0x00007ffff6b16cae in onnxruntime::logging::Logger::Log (this=0x7fffffffcdd0, message=...) at /home/listray/Work/Libs/onnxruntime/include/onnxruntime/core/common/logging/logging.h:291
#3 0x00007ffff6b16ce0 in onnxruntime::logging::Capture::~Capture (this=0x7fffffffc4e0, __in_chrg=<optimized out>) at /home/listray/Work/Libs/onnxruntime/onnxruntime/core/common/logging/capture.cc:57
#4 0x00007ffff6a86301 in onnxruntime::SequentialExecutor::Execute(onnxruntime::SessionState const&, std::vector<int, std::allocator<int> > const&, std::vector<OrtValue, std::allocator<OrtValue> > const&, std::vector<int, std::allocator<int> > const&, std::vector<OrtValue, std::allocator<OrtValue> >&, std::unordered_map<unsigned long, std::function<onnxruntime::common::Status (onnxruntime::TensorShape const&, OrtMemoryInfo const&, OrtValue&, bool&)>, std::hash<unsigned long>, std::equal_to<unsigned long>, std::allocator<std::pair<unsigned long const, std::function<onnxruntime::common::Status (onnxruntime::TensorShape const&, OrtMemoryInfo const&, OrtValue&, bool&)> > > > const&, onnxruntime::logging::Logger const&) (this=0x5555559da4c0, session_state=..., feed_mlvalue_idxs=std::vector of length 1, capacity 1 = {...},
feeds=std::vector of length 1, capacity 1 = {...}, fetch_mlvalue_idxs=std::vector of length 1, capacity 1 = {...}, fetches=std::vector of length 1, capacity 1 = {...},
fetch_allocators=std::unordered_map with 0 elements, logger=...) at /home/listray/Work/Libs/onnxruntime/onnxruntime/core/framework/sequential_executor.cc:309
#5 0x00007ffff6a6d787 in onnxruntime::utils::ExecuteGraphImpl(const onnxruntime::SessionState &, const onnxruntime::FeedsFetchesManager &, const std::vector<OrtValue, std::allocator<OrtValue> > &, std::vector<OrtValue, std::allocator<OrtValue> > &, const std::unordered_map<long unsigned int, std::function<onnxruntime::common::Status(const onnxruntime::TensorShape&, const OrtMemoryInfo&, OrtValue&, bool&)>, std::hash<long unsigned int>, std::equal_to<long unsigned int>, std::allocator<std::pair<long unsigned int const, std::function<onnxruntime::common::Status(const onnxruntime::TensorShape&, const OrtMemoryInfo&, OrtValue&, bool&)> > > > &, ExecutionMode, const bool &, const onnxruntime::logging::Logger &, bool) (session_state=..., feeds_fetches_manager=..., feeds=std::vector of length 1, capacity 1 = {...},
fetches=std::vector of length 1, capacity 1 = {...}, fetch_allocators=std::unordered_map with 0 elements, execution_mode=ORT_SEQUENTIAL, terminate_flag=#0x7fffffffd168: false, logger=...,
only_execute_path_to_fetches=false) at /home/listray/Work/Libs/onnxruntime/onnxruntime/core/framework/utils.cc:454
#6 0x00007ffff6a6df37 in onnxruntime::utils::ExecuteGraph (session_state=..., feeds_fetches_manager=..., feeds=std::vector of length 1, capacity 1 = {...}, fetches=std::vector of length 1, capacity 1 = {...},
execution_mode=ORT_SEQUENTIAL, terminate_flag=#0x7fffffffd168: false, logger=..., only_execute_path_to_fetches=false) at /home/listray/Work/Libs/onnxruntime/onnxruntime/core/framework/utils.cc:513
#7 0x00007ffff63e00c2 in onnxruntime::InferenceSession::Run (this=0x555555917110, run_options=..., feed_names=std::vector of length 1, capacity 1 = {...}, feeds=std::vector of length 1, capacity 1 = {...},
output_names=std::vector of length 1, capacity 1 = {...}, p_fetches=0x7fffffffd120) at /home/listray/Work/Libs/onnxruntime/onnxruntime/core/session/inference_session.cc:1206
#8 0x00007ffff637ecc3 in OrtApis::Run (sess=0x555555917110, run_options=0x0, input_names=0x5555559c1a10, input=0x7fffffffd2f8, input_len=1, output_names1=0x555555a521a0, output_names_len=1,
output=0x555555a3fb30) at /home/listray/Work/Libs/onnxruntime/onnxruntime/core/session/onnxruntime_c_api.cc:506
#9 0x00007ffff7ba6a93 in Ort::Session::Run (this=0x555555916440, run_options=..., input_names=0x5555559c1a10, input_values=0x7fffffffd2f8, input_count=1, output_names=0x555555a521a0,
output_values=0x555555a3fb30, output_count=1) at /home/listray/Work/Libs/onnx_debug/include/onnxruntime_cxx_inline.h:246
#10 0x00007ffff7ba69da in Ort::Session::Run (this=0x555555916440, run_options=..., input_names=0x5555559c1a10, input_values=0x7fffffffd2f8, input_count=1, output_names=0x555555a521a0, output_names_count=1)
at /home/listray/Work/Libs/onnx_debug/include/onnxruntime_cxx_inline.h:237
#11 0x00007ffff7bb0b31 in ai::common::OnnxruntimeGenericModelWrapper<1ul, 1ul>::process (this=0x55555576cb60, tensors=...)
at /home/listray/Work/Projects/ml-library/framework/onnxruntime/onnx_generic_model_wrapper.h:48
...
The downloaded library stops at onnxruntime::logging::LoggingManager::Log.
Here is some wrapper code.
Loading the model:
void load_graph(const ByteBuffer& model)
{
// enviroment maintains thread pools and other state info
Ort::Env env(ORT_LOGGING_LEVEL_WARNING, "Vicue Run");
// initialize session options
Ort::SessionOptions session_options(nullptr);
//session_options.SetIntraOpNumThreads(1);
//Loading models
session = std::make_unique<Ort::Session>(env,
static_cast<const void*>(model.data.get()),
model.length,
session_options);
}
session is wrapper's field:
std::unique_ptr<Ort::Session> session;
ByteBuffer:
struct ByteBuffer
{
std::unique_ptr<char[]> data;
size_t length;
}
Actually wrapper was generic, but this code gets the same error.
std::array<Tensor, outputs> process(std::array<Tensor, inputs> tensors) override
{
std::array<Tensor, outputs> result;
// maybe this should be different if we have multiple input
Ort::AllocatorWithDefaultOptions allocator;
auto memory_info = Ort::MemoryInfo::CreateCpu(OrtArenaAllocator, OrtMemTypeDefault);
if(outputs == 1 && inputs == 1) {
auto input_shape = session->GetInputTypeInfo(0).GetTensorTypeAndShapeInfo().GetShape();
Ort::Value input_tensor = Ort::Value::CreateTensor<float>(memory_info,
tensors[0].data.data(),
tensors[0].data.size(),
input_shape.data(),
input_shape.size());
std::vector<const char*> input_node_names = { session->GetInputName(0, allocator) };
std::vector<const char*> output_node_names = { session->GetOutputName(0, allocator) };
std::vector<Ort::Value> output_tensors = session->Run(Ort::RunOptions{nullptr},
input_node_names.data(),
&input_tensor,
inputs,
output_node_names.data(),
outputs);
One strange thing that I don't understand. During an error i see this:
(gdb) print this
$4 = (onnxruntime::logging::Capture * const) 0x7fffffffc4e0
(gdb) print this->logger_->logging_manager_->sink_
$5 = std::unique_ptr<onnxruntime::logging::ISink> = {get() = 0x5555559154c0}
(gdb) print *(this->logger_->logging_manager_->sink_)
$6 = {_vptr.ISink = 0x0}
When the logger is created, its *(logging_manager_->sink_) is also {_vptr.ISink = 0x0}.
I do not have the complete idea of your code structure but try making Ort::Env variable static.
Simple application causes segfault when I try to connect to the same database twice. It works fine with local database but crashes on second call to open() with any remote tunnel. What could be the cause? Am I doing something I should not be doing?
Obviously this is made up example but in reality I'm trying to manage db connections for a bigger app and manager does similar open/close cycle when requested.
QT version is 5.7.0. Compiled from sources to get better stack trace but not sure if it helped.
Remote MySQL is 5.6.27 (Amazon RDS actually), local is 5.7.17.
It's not eactly happening because I use tunnels. I can create a tunnel to my local database and the app works fine, no crashes.
If I tunnel local database to remote machine and then tunnel back from it to local, app still works. So it's not the latency either.
Code:
#include <QCoreApplication>
#include <QSqlDatabase>
void initDb(QSqlDatabase db) {
QString connectionHost = "127.0.0.1";
int port = 3311; // local tunnel
QString user = "mydbuser";
QString password = "mydbpassword";
QString database = "mydbname";
db.setHostName(connectionHost);
db.setPort(port);
db.setUserName(user);
db.setPassword(password);
db.setDatabaseName(database);
}
int main(int argc, char *argv[]) {
QString name1 = "db1", name2 = "db2";
{
QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL", name1);
initDb(db);
db.open();
db.close();
}
QSqlDatabase::removeDatabase(name1);
{
QSqlDatabase db1 = QSqlDatabase::addDatabase("QMYSQL", name2);
initDb(db1);
db1.open();
db1.close();
}
QSqlDatabase::removeDatabase(name2);
return 0;
}
Trace:
Thread 1 (Thread 0x7f7603ee3740 (LWP 3505)):
#0 __GI___pthread_mutex_lock (mutex=0x20) at ../nptl/pthread_mutex_lock.c:67
__PRETTY_FUNCTION__ = "__pthread_mutex_lock"
type = <optimized out>
id = <optimized out>
#1 0x00007f75ff228d79 in ?? () from /usr/lib/x86_64-linux-gnu/libmysqlclient.so.20
No symbol table info available.
#2 0x00007f75ff1ff660 in ?? () from /usr/lib/x86_64-linux-gnu/libmysqlclient.so.20
No symbol table info available.
#3 0x00007f75ff1d65e5 in mysql_real_connect () from /usr/lib/x86_64-linux-gnu/libmysqlclient.so.20
No symbol table info available.
#4 0x00007f7603f06a54 in QMYSQLDriver::open (this=0xbd4c90, db=..., user=..., password=..., host=..., port=3311, connOpts=...) at ../../../sql/drivers/mysql/qsql_mysql.cpp:1393
d = 0xbd5ea0
optionFlags = 65536
opts = {<QList<QString>> = {<QListSpecialMethods<QString>> = {<No data fields>}, {p = {static shared_null = {ref = {atomic = {_q_value = {<std::__atomic_base<int>> = {static _S_alignment = 4, _M_i = -1}, <No data fields>}}}, alloc = 0, begin = 0, end = 0, array = {0x0}}, d = 0x7f7603b0ffb0 <QListData::shared_null>}, d = 0x7f7603b0ffb0 <QListData::shared_null>}}, <No data fields>}
unixSocket = {static null = {<No data fields>}, d = 0x7f7603b0c140 <QArrayData::shared_null>}
sslCert = {static null = {<No data fields>}, d = 0x7f7603b0c140 <QArrayData::shared_null>}
sslCA = {static null = {<No data fields>}, d = 0x7f7603b0c140 <QArrayData::shared_null>}
sslKey = {static null = {<No data fields>}, d = 0x7f7603b0c140 <QArrayData::shared_null>}
sslCAPath = {static null = {<No data fields>}, d = 0x7f7603b0c140 <QArrayData::shared_null>}
sslCipher = {static null = {<No data fields>}, d = 0x7f7603b0c140 <QArrayData::shared_null>}
reconnect = 0 '\000'
connectTimeout = 0
readTimeout = 0
writeTimeout = 0
__PRETTY_FUNCTION__ = "virtual bool QMYSQLDriver::open(const QString&, const QString&, const QString&, const QString&, int, const QString&)"
mysql = 0x7ffe4d0aee80
#5 0x00007f7603f2d4b9 in QSqlDatabase::open (this=0x7ffe4d0aef70) at kernel/qsqldatabase.cpp:835
No locals.
#6 0x00000000004010d0 in main (argc=1, argv=0x7ffe4d0af098) at ../main.cpp:31
db1 = {static defaultConnection = 0x7f7603f52bf5 "qt_sql_default_connection", d = 0xbbdee0}
name1 = {static null = {<No data fields>}, d = 0xbbde50}
name2 = {static null = {<No data fields>}, d = 0xbbde80}
I recently encountering a pretty weird c++ STL sort behavior when I tried to apply a greater than compare function sort on a vector of strings, the detailed implementation could be found below:
//Compare the modify time of two files
bool cmp_modifytime(const base::String &file1, const base::String &file2)
{
struct stat statbuf1, statbuf2;
stat(file1.getBuffer(), &statbuf1);
stat(file2.getBuffer(), &statbuf2);
return statbuf1.st_mtime > statbuf2.st_mtime;
}
main routine:
std::vector<base::String> lFiles;
getFilesFromDir(dir, lFiles);
int fileCount = lFiles.size();
for(int i = 0; i <fileCount; i++)
{
tmp_str = dir;
tmp_str.append("/");
tmp_str.append(lFiles[i]);
lFiles[i] = tmp_str;
}
sort(lFiles.begin(), lFiles.end(), cmp_modifytime);
When I decode the crash, the backtrace looks like the following:
#0 0xf49a8940 in typeinfo for base::AString () from xxx
#1 0xf4919262 in cmp_modifytime (file1=..., file2=...) at xxx
#2 0xf491f91a in std::__unguarded_partition<__gnu_cxx::__normal_iterator<base::String*, std::vector<base::String> >, base::String, bool (*)(base::String const&, base::String const&)> (__first=..., __last=..., __pivot=..., __comp=0xf491923b <cmp_modifytime(base::String const&, base::String const&)>)
at xxx
#3 0xf491e5da in std::__unguarded_partition_pivot<__gnu_cxx::__normal_iterator<base::String*, std::vector<base::String> >, bool (*)(base::String const&, base::String const&)>
(__first=..., __last=..., __comp=0xf491923b <cmp_modifytime(base::String const&, base::String const&)>)
at xxx
#4 0xf491d0cc in std::__introsort_loop<__gnu_cxx::__normal_iterator<base::String*, std::vector<base::String> >, int, bool (*)(base::String const&, base::String const&)> (
__first=..., __last=..., __depth_limit=7, __comp=0xf491923b <cmp_modifytime(base::String const&, base::String const&)>)
at xxx
#5 0xf491d0ef in std::__introsort_loop<__gnu_cxx::__normal_iterator<base::String*, std::vector<base::String> >, int, bool (*)(base::String const&, base::String const&)> (
__first=..., __last=..., __depth_limit=8, __comp=0xf491923b <cmp_modifytime(base::String const&, base::String const&)>)
at xxx
#6 0xf491d0ef in std::__introsort_loop<__gnu_cxx::__normal_iterator<base::String*, std::vector<base::String> >, int, bool (*)(base::String const&, base::String const&)> (
__first=..., __last=..., __depth_limit=9, __comp=0xf491923b <cmp_modifytime(base::String const&, base::String const&)>)
at xxx
#7 0xf491c198 in std::sort<__gnu_cxx::__normal_iterator<base::String*, std::vector<base::String> >, bool (*)(base::String const&, base::String const&)> (__first=...,
__last=..., __comp=0xf491923b <cmp_modifytime(base::String const&, base::String const&)>)
at xxx
#8 0xf4919521 in main routine
The crash happened in the compare function, and interestingly I found that one of the input String object is an empty string:
(gdb) p file1
$1 = (const base::String &) #0x11db6180: {<base::Object> = {_vptr.Object = 0xf49a88e8}, <base::AString> = {_vptr.AString = 0xf49a8908}, buffer = 0x0, hashValue = 4294967295, size = -1, immutable = false}
(gdb) p file2
$2 = (const base::String &) #0x11db5f58: {<base::Object> = {_vptr.Object = 0xf49a8888}, <base::AString> = {_vptr.AString = 0xf49a88c8}, buffer = 0x11db6ba8 "testString123", hashValue = 4294967295, size = 13, immutable = false}
(gdb) p &file2
$3 = (const base::String *) 0x11db5f58
(gdb) p &file1
$4 = (const base::String *) 0x11db6180
And what's more interesting is that this empty string address is the same as the _M_finish of the vector I tried to do the sort, which means somehow sort takes the vector.end() into the compare function:
(gdb) p lFiles._M_impl._M_finish
$7 = (std::allocator<base::String>::pointer) 0x11db6180
This should never happen in my understanding.
My program appears to run just fine most of the time, but occasionally I get a segmentation fault.
boost version = 1.41.0
running on RHEL 4
compiled with GCC 3.4.6
Backtrace:
#0 0x08138546 in boost::asio::detail::posix_fd_set_adapter::is_set (this=0xb74ed020, descriptor=-1)
at /home/scottl/boost_1_41_0/boost/asio/detail/posix_fd_set_adapter.hpp:57
__result = -1 'ÿ'
#1 0x0813e1b0 in boost::asio::detail::reactor_op_queue::perform_operations_for_descriptors (this=0x97f3b6c, descriptors=#0xb74ed020, result=#0xb74ecec8)
at /home/scottl/boost_1_41_0/boost/asio/detail/reactor_op_queue.hpp:204
op_iter = {_M_node = 0xb4169aa0}
i = {_M_node = 0x97f3b74}
#2 0x081382ca in boost::asio::detail::select_reactor::run (this=0x97f3b08, block=true)
at /home/scottl/boost_1_41_0/boost/asio/detail/select_reactor.hpp:388
read_fds = {fd_set_ = {fds_bits = {16, 0 }}, max_descriptor_ = 65}
write_fds = {fd_set_ = {fds_bits = {0 }}, max_descriptor_ = -1}
retval = 1
lock = { = {}, mutex_ = #0x97f3b1c, locked_ = true}
except_fds = {fd_set_ = {fds_bits = {0 }}, max_descriptor_ = -1}
max_fd = 65
tv_buf = {tv_sec = 0, tv_usec = 710000}
tv = (timeval *) 0xb74ecf88
ec = {m_val = 0, m_cat = 0x81f2c24}
sb = { = {}, blocked_ = true, old_mask_ = {__val = {0, 0, 134590223,
3075395548, 3075395548, 3075395464, 134729792, 3075395360, 135890240, 3075395368, 134593920, 3075395544, 135890240,
3075395384, 134599542, 3020998404, 135890240, 3075395400, 134614095, 3075395544, 4, 3075395416, 134548135, 3021172996,
4294967295, 3075395432, 134692921, 3075395504, 0, 3075395448, 134548107, 3021172992}}}
#3 0x0812eb45 in boost::asio::detail::task_io_service >::do_one (this=0x97f3a70,
lock=#0xb74ed230, this_idle_thread=0xb74ed240, ec=#0xb74ed2c0)
at /home/scottl/boost_1_41_0/boost/asio/detail/task_io_service.hpp:260
more_handlers = false
c = {lock_ = #0xb74ed230, task_io_service_ = #0x97f3a70}
h = (boost::asio::detail::handler_queue::handler *) 0x97f3aa0
polling = false
task_has_run = true
#4 0x0812765f in boost::asio::detail::task_io_service >::run (this=0x97f3a70,
ec=#0xb74ed2c0) at /home/scottl/boost_1_41_0/boost/asio/detail/task_io_service.hpp:103
ctx = { = {}, owner_ = 0x97f3a70, next_ = 0x0}
this_idle_thread = {wakeup_event = { = {}, cond_ = {__c_lock = {
__status = 0, __spinlock = 22446}, __c_waiting = 0x2bd7,
__padding = "\000\000\000\000×+\000\000\000\000\000\000×+\000\000\000\000\000\000\204:\177\t\000\000\000", __align = 0},
signalled_ = true}, next = 0x0}
lock = { = {}, mutex_ = #0x97f3a84, locked_ = false}
n = 11420
#5 0x08125e99 in boost::asio::io_service::run (this=0x97ebbcc) at /home/scottl/boost_1_41_0/boost/asio/impl/io_service.ipp:58
ec = {m_val = 0, m_cat = 0x81f2c24}
s = 8
#6 0x08154424 in boost::_mfi::mf0::operator() (this=0x9800870, p=0x97ebbcc)
at /home/scottl/boost_1_41_0/boost/bind/mem_fn_template.hpp:49
No locals.
#7 0x08154331 in boost::_bi::list1 >::operator(), boost::_bi::list0> (this=0x9800878, f=#0x9800870, a=#0xb74ed337)
at /home/scottl/boost_1_41_0/boost/bind/bind.hpp:236
No locals.
#8 0x081541e5 in boost::_bi::bind_t, boost::_bi::list1 > >::operator() (this=0x9800870) at /home/scottl/boost_1_41_0/boost/bind/bind_template.hpp:20
a = {}
#9 0x08154075 in boost::detail::thread_data, boost::_bi::list1 > > >::run (this=0x98007a0)
at /home/scottl/boost_1_41_0/boost/thread/detail/thread.hpp:56
No locals.
#10 0x0816fefd in thread_proxy () at /usr/lib/gcc/i386-redhat-linux/3.4.6/../../../../include/c++/3.4.6/bits/locale_facets.tcc:2443
__ioinit = {static _S_refcount = , static _S_synced_with_stdio = }
---Type to continue, or q to quit---
typeinfo for common::RuntimeException = {}
typeinfo name for common::RuntimeException = "N6common16RuntimeExceptionE"
#11 0x00af23cc in start_thread () from /lib/tls/libpthread.so.0
No symbol table info available.
#12 0x00a5c96e in __init_misc () from /lib/tls/libc.so.6
No symbol table info available.
Without seeing the code in question, I can only guess, but I've had asio crash on several occasions due to the object whose method has been passed (via boost::bind) to asio has been deleted before asio calls the method.