Deleting QGraphicsItem with QGraphicsEffect leads to segfault - c++

The following program paints a red background. Pressing the left mouse button paints a white rectangle onto it. The rectangle has a child rectangle and a QGraphicsDropShadowEffect. (QGraphicsOpacityEffect and QGraphicsColorizeEffect also lead to the problem, but less frequently.)
Pressing the right mouse button removes the white rectangle.
Sometimes when removing the rectangle it causes a segmentation fault.
This does not happen if the QGraphicsDropShadowEffect is not applied. It also does not happen when there either is no child item in MyRect or the background is ommited.
(When searching for this issue, I found several hints that a segfault like this could be related to changing the boundingRect() of an item without calling prepareGeometryChange().)
I am really at a loss here. This is part of a bigger project and I boiled it down to the following example:
Main.cc:
#include<QApplication>
#include<QGraphicsView>
#include<QGraphicsScene>
#include<QGraphicsSceneMouseEvent>
#include<QGraphicsRectItem>
#include<QGraphicsDropShadowEffect>
#include<QScreen>
class MyRect: public QGraphicsRectItem
{
public:
MyRect(QGraphicsItem* parent = nullptr):
QGraphicsRectItem{QRectF{0.0f, 0.0f, 100.0f, 100.0f}, parent}
{
setPen(QPen{Qt::white});
setBrush(QBrush{Qt::white, Qt::SolidPattern});
my_child_=new QGraphicsRectItem{this};
}
private:
QGraphicsRectItem* my_child_=nullptr;
};
class MyScene: public QGraphicsScene
{
public:
MyScene()
{
background_=new QGraphicsRectItem{0.0f, 0.0f, 500.0f, 500.0f};
background_->setPen(QPen{Qt::white});
background_->setBrush(QBrush{Qt::red, Qt::SolidPattern});
addItem(background_);
}
void mouseReleaseEvent(QGraphicsSceneMouseEvent* me) override
{
if (me->button()==Qt::LeftButton)
{
if (my_rect_==nullptr)
{
my_rect_=new MyRect{};
shadow_=new QGraphicsDropShadowEffect{};
shadow_->setBlurRadius(15.0f);
my_rect_->setGraphicsEffect(shadow_);
addItem(my_rect_);
my_rect_->setPos(me->scenePos());
}
}
else if (me->button()==Qt::RightButton)
{
if (my_rect_!=nullptr)
{
removeItem(my_rect_);
my_rect_->setGraphicsEffect(0);
shadow_=nullptr;
delete my_rect_;
my_rect_=nullptr;
}
}
else
{
QGraphicsScene::mouseReleaseEvent(me);
}
}
private:
QGraphicsRectItem* background_=nullptr;
MyRect* my_rect_=nullptr;
QGraphicsDropShadowEffect* shadow_=nullptr;
};
int
main(int argc, char** argv)
{
QApplication qapp{argc, argv};
QGraphicsView view;
MyScene scene;
QRect rect=QGuiApplication::primaryScreen()->geometry();
scene.setSceneRect(0.0f, 0.0f, rect.width(), rect.height());
view.setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
view.setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
view.setFrameShape(QFrame::NoFrame);
view.setBackgroundBrush(QBrush(Qt::black, Qt::SolidPattern));
view.setScene(&scene);
view.showFullScreen();
return qapp.exec();
}
Compiler call:
g++ --std=c++14 -fPIC -Wall -Woverloaded-virtual -Werror -pedantic -g -O0 -fPIC -I/usr/include/x86_64-linux-gnu/qt5/QtGui -I/usr/include/x86_64-linux-gnu/qt5/QtWidgets -I/usr/include/x86_64-linux-gnu/qt5/QtCore -I/usr/include/x86_64-linux-gnu/qt5 -o test Main.cc -lQt5Gui -lQt5Core -lQt5Widgets
Backtrace:
#0 0x0000555555a9a840 in ?? ()
#1 0x00007ffff71e017c in ?? () from /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
#2 0x00007ffff71e0a3a in ?? () from /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
#3 0x00007ffff720289a in QGraphicsView::paintEvent(QPaintEvent*) () from /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
#4 0x00007ffff6f10278 in QWidget::event(QEvent*) () from /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
#5 0x00007ffff6ff89fe in QFrame::event(QEvent*) () from /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
#6 0x00007ffff72013ab in QGraphicsView::viewportEvent(QEvent*) () from /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
#7 0x00007ffff7650701 in QCoreApplicationPrivate::sendThroughObjectEventFilters(QObject*, QEvent*) () from /usr/lib/x86_64-linux-gnu/libQt5Core.so.5
#8 0x00007ffff6ec8b65 in QApplicationPrivate::notify_helper(QObject*, QEvent*) () from /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
#9 0x00007ffff6ed0341 in QApplication::notify(QObject*, QEvent*) () from /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
#10 0x00007ffff76509a0 in QCoreApplication::notifyInternal2(QObject*, QEvent*) () from /usr/lib/x86_64-linux-gnu/libQt5Core.so.5
#11 0x00007ffff6f08fda in QWidgetPrivate::sendPaintEvent(QRegion const&) () from /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
#12 0x00007ffff6f09646 in QWidgetPrivate::drawWidget(QPaintDevice*, QRegion const&, QPoint const&, int, QPainter*, QWidgetBackingStore*) ()
from /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
#13 0x00007ffff6ed8f1e in ?? () from /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
#14 0x00007ffff6ed9147 in ?? () from /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
#15 0x00007ffff6ef7f8f in QWidgetPrivate::syncBackingStore() () from /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
#16 0x00007ffff6f10348 in QWidget::event(QEvent*) () from /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
#17 0x00007ffff6ff89fe in QFrame::event(QEvent*) () from /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
#18 0x00007ffff7081de3 in QAbstractScrollArea::event(QEvent*) () from /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
#19 0x00007ffff6ec8b8c in QApplicationPrivate::notify_helper(QObject*, QEvent*) () from /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
#20 0x00007ffff6ed0341 in QApplication::notify(QObject*, QEvent*) () from /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
#21 0x00007ffff76509a0 in QCoreApplication::notifyInternal2(QObject*, QEvent*) () from /usr/lib/x86_64-linux-gnu/libQt5Core.so.5
#22 0x00007ffff765312d in QCoreApplicationPrivate::sendPostedEvents(QObject*, int, QThreadData*) () from /usr/lib/x86_64-linux-gnu/libQt5Core.so.5
#23 0x00007ffff71d2a22 in ?? () from /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
#24 0x00007ffff71d8299 in ?? () from /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
#25 0x00007ffff767d459 in QObject::event(QEvent*) () from /usr/lib/x86_64-linux-gnu/libQt5Core.so.5
#26 0x00007ffff71e4e6b in QGraphicsScene::event(QEvent*) () from /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
#27 0x00007ffff6ec8b8c in QApplicationPrivate::notify_helper(QObject*, QEvent*) () from /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
#28 0x00007ffff6ed0341 in QApplication::notify(QObject*, QEvent*) () from /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
#29 0x00007ffff76509a0 in QCoreApplication::notifyInternal2(QObject*, QEvent*) () from /usr/lib/x86_64-linux-gnu/libQt5Core.so.5
#30 0x00007ffff765312d in QCoreApplicationPrivate::sendPostedEvents(QObject*, int, QThreadData*) () from /usr/lib/x86_64-linux-gnu/libQt5Core.so.5
#31 0x00007ffff76a4c03 in ?? () from /usr/lib/x86_64-linux-gnu/libQt5Core.so.5
#32 0x00007ffff446f7f7 in g_main_context_dispatch () from /lib/x86_64-linux-gnu/libglib-2.0.so.0
#33 0x00007ffff446fa60 in ?? () from /lib/x86_64-linux-gnu/libglib-2.0.so.0
#34 0x00007ffff446fb0c in g_main_context_iteration () from /lib/x86_64-linux-gnu/libglib-2.0.so.0
#35 0x00007ffff76a500f in QEventDispatcherGlib::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) () from /usr/lib/x86_64-linux-gnu/libQt5Core.so.5
#36 0x00007ffff764e98a in QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) () from /usr/lib/x86_64-linux-gnu/libQt5Core.so.5
#37 0x00007ffff76570fc in QCoreApplication::exec() () from /usr/lib/x86_64-linux-gnu/libQt5Core.so.5
#38 0x000055555555768b in main (argc=1, argv=0x7fffffffe5b8) at Main.cc:89
EDIT: I rewritten the code example for better readability.

As I was educated on on the Qt forums this is not expected behaviour and might be a bug in Qt.
The best workaround is to call QGraphicsItem::prepareGeometryChange() on my_rect_ before removing it from the scene. This might be done be exposing the protected prepareGeometryChange() or by calling it inside ~MyRect() and then simply deleting my_rect_ without calling QGraphicsScene::removeItem(). ~QGraphicsItem(), which of course is called after ~MyRect(), will automatically remove the item from the scene.

Related

How to interpret the template function signature of backtrace in GDB?

The output of backtrace of GDB is pretty messy, especially for template.
For instance:
Thread 2 (LWP 100146 of process 1245):
#0 thr_new () at thr_new.S:3
#1 0x000000080025c3da in _pthread_create (thread=0x7fffdfffd880, attr=<optimized out>, start_routine=0x205500 <void* std::__1::__thread_proxy<std::__1::tuple<std::__1::unique_ptr<std::__1::__thread_struct, std::__1::default_delete<std::__1::__thread_struct> >, void (std::__1::__async_assoc_state<void, std::__1::__async_func<func2(std::__1::atomic<long>&)::$_0> >::*)(), std::__1::__async_assoc_state<void, std::__1::__async_func<func2(std::__1::atomic<long>&)::$_0> >*> >(void*)>, arg=0x8007fa8e0) at /usr/src/lib/libthr/thread/thr_create.c:188
#2 0x0000000000204e40 in std::__1::thread::thread<void (std::__1::__async_assoc_state<void, std::__1::__async_func<func2(std::__1::atomic<long>&)::$_0> >::*)(), std::__1::__async_assoc_state<void, std::__1::__async_func<func2(std::__1::atomic<long>&)::$_0> >*, void>(void (std::__1::__async_assoc_state<void, std::__1::__async_func<func2(std::__1::atomic<long>&)::$_0> >::*&&)(), std::__1::__async_assoc_state<void, std::__1::__async_func<func2(std::__1::atomic<long>&)::$_0> >*&&) ()
#3 0x0000000000204309 in std::__1::future<void> std::__1::__make_async_assoc_state<void, std::__1::__async_func<func2(std::__1::atomic<long>&)::$_0> >(std::__1::__async_func<func2(std::__1::atomic<long>&)::$_0>&&) ()
#4 0x00000000002035ea in std::__1::future<std::__1::__invoke_of<std::__1::decay<func2(std::__1::atomic<long>&)::$_0>::type>::type> std::__1::async<func2(std::__1::atomic<long>&)::$_0>(std::__1::launch, func2(std::__1::atomic<long>&)::$_0&&) ()
#5 0x0000000000203462 in func2(std::__1::atomic<long>&) ()
#6 0x0000000000206f18 in main::$_1::operator()() const ()
#7 0x0000000000206eed in void std::__1::__async_func<main::$_1>::__execute<>(std::__1::__tuple_indices<>) ()
#8 0x0000000000206ea5 in std::__1::__async_func<main::$_1>::operator()() ()
#9 0x0000000000206df3 in std::__1::__async_assoc_state<void, std::__1::__async_func<main::$_1> >::__execute() ()
#10 0x0000000000207183 in void* std::__1::__thread_proxy<std::__1::tuple<std::__1::unique_ptr<std::__1::__thread_struct, std::__1::default_delete<std::__1::__thread_struct> >, void (std::__1::__async_assoc_state<void, std::__1::__async_func<main::$_1> >::*)(), std::__1::__async_assoc_state<void, std::__1::__async_func<main::$_1> >*> >(void*) ()
#11 0x000000080025c776 in thread_start (curthread=0x8007de500) at /usr/src/lib/libthr/thread/thr_create.c:292
#12 0x0000000000000000 in ?? ()
Backtrace stopped: Cannot access memory at address 0x7fffdfffe000
In frame #8, there are three pairs of parentheses, std::__1::__async_func<main::$_1>::operator()() () what do they mean exactly?
Frame #8 doesn't have debug info, so GDB can't accurately describe it.
Consider this test case:
struct Foo {
int operator()(void) {
return 1; // line 3
}
};
int main()
{
return Foo()();
}
When compiled with g++ -g t.cc and at breakpoint on line 3, this is what GDB displays:
Breakpoint 1, Foo::operator() (this=0x7fffffffdcff) at t.cc:3
3 return 1;
(gdb) bt
#0 Foo::operator() (this=0x7fffffffdcff) at t.cc:3
#1 0x0000555555555139 in main () at t.cc:10
But compile the same source without -g, set a breakpoint on _ZN3FooclEv, and this is what you will see:
Breakpoint 1, 0x0000555555555140 in Foo::operator()() ()
(gdb) bt
#0 0x0000555555555140 in Foo::operator()() ()
#1 0x0000555555555139 in main ()
The first two sets of parenthesis come from demangling the symbol:
c++filt _ZN3FooclEv
Foo::operator()()
The third set is added by GDB because the symbol being displayed is in the .text section and is assumed to be a function.

std::async causes deadlock?

I was trying to use std::async in a heavy workload application to improve the performance but I encountered deadlock from time to time. I debugged for a very long time and I am almost certain that my code was fine and it seemed something wrong with std library.
So I wrote a simple test program to testify:
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <future>
#include <string>
#include <mutex>
#include <unistd.h>
#include <atomic>
#include <iomanip>
std::atomic_long numbers[6];
void add(std::atomic_long& n)
{
++n;
}
void func2(std::atomic_long& n)
{
for (auto i = 0L; i < 1000000000000L; ++i)
{
std::async(std::launch::async, [&] {add(n);}); // Small task, I want to run them simultaneously
}
}
int main()
{
std::vector<std::future<void>> results;
for (int i = 0; i < 6; ++i)
{
auto& n = numbers[i];
results.push_back(std::async(std::launch::async, [&n] {func2(n);}));
}
while (true)
{
sleep(1);
for (int i = 0; i < 6; ++i)
std::cout << std::setw(20) << numbers[i] << " ";
std::cout << std::endl;
}
for (auto& r : results)
{
r.wait();
}
return 0;
}
This program will produce output like this:
763700 779819 754005 763287 767713 748994
768822 785172 759678 769393 772956 754469
773529 789382 763524 772704 776398 757864
778560 794419 768580 777507 781542 762991
782056 795578 771704 780554 784865 766162
801633 812610 788111 802617 803661 784894
After a time (minutes or hours), if there was a deadlock, the output will be like this:
4435337 4452421 4507907 4501378 2549550 4462899
4441213 4457648 4514424 4506626 2549550 4468019
4446301 4462675 4519272 4511889 2549550 4473266
4453940 4470304 4526382 4519513 2549550 4480872
4461095 4477708 4533272 4526901 2549550 4488313
4470974 4488287 4543442 4537286 2549550 4498733
The fifth column was frozen.
After one day, it became this:
23934912 23967635 24007250 23931203 2549550 3249788689
23934912 23967635 24007250 23931203 2549550 3249816818
23934912 23967635 24007250 23931203 2549550 3249835009
23934912 23967635 24007250 23931203 2549550 3249860262
23934912 23967635 24007250 23931203 2549550 3249894331
Almost all columns froze except last column. It look really odd.
I ran it on Linux, macOS, FreeBSD, and the result was:
macOS:10.15.2, Clang:11.0.0, no deadlock
FreeBSD:12.0, Clang:6.0.1, deadlock
Linux: ubuntu 5.0.0-37, g++:7.4.0, no deadlock
Linux: ubuntu 4.4.0-21, Clang:3.8.0, deadlock
In the gdb, the call stack was:
(gdb) thread apply all bt
Thread 10 (LWP 100467 of process 37763):
#0 0x000000080025c630 in ?? () from /lib/libthr.so.3
#1 0x0000000000000000 in ?? ()
Backtrace stopped: Cannot access memory at address 0x7fff4ad57000
Thread 9 (LWP 100464 of process 37763):
#0 0x000000080046fafa in _umtx_op () from /lib/libc.so.7
#1 0x0000000800264912 in ?? () from /lib/libthr.so.3
#2 0x000000080031f9f9 in std::__1::mutex::unlock() () from /usr/lib/libc++.so.1
#3 0x00000008002e8f55 in std::__1::__assoc_sub_state::set_value() () from /usr/lib/libc++.so.1
#4 0x00000000002053e1 in std::__1::__async_assoc_state<void, std::__1::__async_func<func2(std::__1::atomic<long>&)::$_0> >::__execute() ()
#5 0x0000000000205763 in void* std::__1::__thread_proxy<std::__1::tuple<std::__1::unique_ptr<std::__1::__thread_struct, std::__1::default_delete<std::__1::__thread_struct> >, void (std::__1::__async_assoc_state<void, std::__1::__async_func<func2(std::__1::atomic<long>&)::$_0> >::*)(), std::__1::__async_assoc_state<void, std::__1::__async_func<func2(std::__1::atomic<long>&)::$_0> >*> >(void*) ()
#6 0x000000080025c776 in ?? () from /lib/libthr.so.3
#7 0x0000000000000000 in ?? ()
Backtrace stopped: Cannot access memory at address 0x7fff6944a000
Thread 8 (LWP 100431 of process 37763):
#0 0x000000080046fafa in _umtx_op () from /lib/libc.so.7
#1 0x0000000800264912 in ?? () from /lib/libthr.so.3
#2 0x000000080031f9f9 in std::__1::mutex::unlock() () from /usr/lib/libc++.so.1
#3 0x00000008002e8f55 in std::__1::__assoc_sub_state::set_value() () from /usr/lib/libc++.so.1
#4 0x00000000002053e1 in std::__1::__async_assoc_state<void, std::__1::__async_func<func2(std::__1::atomic<long>&)::$_0> >::__execute() ()
#5 0x0000000000205763 in void* std::__1::__thread_proxy<std::__1::tuple<std::__1::unique_ptr<std::__1::__thread_struct, std::__1::default_delete<std::__1::__thread_struct> >, void (std::__1::__async_assoc_state<void, std::__1::__async_func<func2(std::__1::atomic<long>&)::$_0> >::*)(), std::__1::__async_assoc_state<void, std::__1::__async_func<func2(std::__1::atomic<long>&)::$_0> >*> >(void*) ()
#6 0x000000080025c776 in ?? () from /lib/libthr.so.3
#7 0x0000000000000000 in ?? ()
Backtrace stopped: Cannot access memory at address 0x7fffc371a000
Thread 7 (LWP 100657 of process 37763):
#0 0x000000080026a66c in ?? () from /lib/libthr.so.3
#1 0x000000080025e731 in ?? () from /lib/libthr.so.3
#2 0x0000000800268388 in ?? () from /lib/libthr.so.3
#3 0x000000080032de72 in std::__1::condition_variable::wait(std::__1::unique_lock<std::__1::mutex>&) () from /usr/lib/libc++.so.1
#4 0x00000008002e971b in std::__1::__assoc_sub_state::wait() () from /usr/lib/libc++.so.1
#5 0x0000000000205389 in std::__1::__async_assoc_state<void, std::__1::__async_func<func2(std::__1::atomic<long>&)::$_0> >::__on_zero_shared() ()
#6 0x000000000020346b in func2(std::__1::atomic<long>&) ()
#7 0x0000000000206f18 in main::$_1::operator()() const ()
#8 0x0000000000206eed in void std::__1::__async_func<main::$_1>::__execute<>(std::__1::__tuple_indices<>) ()
#9 0x0000000000206ea5 in std::__1::__async_func<main::$_1>::operator()() ()
#10 0x0000000000206df3 in std::__1::__async_assoc_state<void, std::__1::__async_func<main::$_1> >::__execute() ()
#11 0x0000000000207183 in void* std::__1::__thread_proxy<std::__1::tuple<std::__1::unique_ptr<std::__1::__thread_struct, std::__1::default_delete<std::__1::__thread_struct> >, void (std::__1::__async_assoc_state<void, std::__1::__async_func<main::$_1> >::*)(), std::__1::__async_assoc_state<void, std::__1::__async_func<main::$_1> >*> >(void*) ()
#12 0x000000080025c776 in ?? () from /lib/libthr.so.3
#13 0x0000000000000000 in ?? ()
Backtrace stopped: Cannot access memory at address 0x7fffdf5f9000
Thread 6 (LWP 100656 of process 37763):
#0 0x000000080026a66c in ?? () from /lib/libthr.so.3
#1 0x000000080025e731 in ?? () from /lib/libthr.so.3
#2 0x0000000800268388 in ?? () from /lib/libthr.so.3
#3 0x000000080032de72 in std::__1::condition_variable::wait(std::__1::unique_lock<std::__1::mutex>&) () from /usr/lib/libc++.so.1
#4 0x00000008002e971b in std::__1::__assoc_sub_state::wait() () from /usr/lib/libc++.so.1
#5 0x0000000000205389 in std::__1::__async_assoc_state<void, std::__1::__async_func<func2(std::__1::atomic<long>&)::$_0> >::__on_zero_shared() ()
#6 0x0000000000207a22 in std::__1::__release_shared_count::operator()(std::__1::__shared_count*) ()
#7 0x00000000002044f4 in std::__1::future<void> std::__1::__make_async_assoc_state<void, std::__1::__async_func<func2(std::__1::atomic<long>&)::$_0> >(std::__1::__async_func<func2(std::__1::atomic<long>&)::$_0>&&) ()
#8 0x00000000002035ea in std::__1::future<std::__1::__invoke_of<std::__1::decay<func2(std::__1::atomic<long>&)::$_0>::type>::type> std::__1::async<func2(std::__1::atomic<long>&)::$_0>(std::__1::launch, func2(std::__1::atomic<long>&)::$_0&&) ()
#9 0x0000000000203462 in func2(std::__1::atomic<long>&) ()
#10 0x0000000000206f18 in main::$_1::operator()() const ()
#11 0x0000000000206eed in void std::__1::__async_func<main::$_1>::__execute<>(std::__1::__tuple_indices<>) ()
#12 0x0000000000206ea5 in std::__1::__async_func<main::$_1>::operator()() ()
#13 0x0000000000206df3 in std::__1::__async_assoc_state<void, std::__1::__async_func<main::$_1> >::__execute() ()
#14 0x0000000000207183 in void* std::__1::__thread_proxy<std::__1::tuple<std::__1::unique_ptr<std::__1::__thread_struct, std::__1::default_delete<std::__1::__thread_struct> >, void (std::__1::__async_assoc_state<void, std::__1::__async_func<main::$_1> >::*)(), std::__1::__async_assoc_state<void, std::__1::__async_func<main::$_1> >*> >(void*) ()
#15 0x000000080025c776 in ?? () from /lib/libthr.so.3
#16 0x0000000000000000 in ?? ()
Backtrace stopped: Cannot access memory at address 0x7fffdf7fa000
Thread 5 (LWP 100655 of process 37763):
#0 0x000000080026a66c in ?? () from /lib/libthr.so.3
#1 0x000000080025e731 in ?? () from /lib/libthr.so.3
#2 0x0000000800268388 in ?? () from /lib/libthr.so.3
#3 0x000000080032de72 in std::__1::condition_variable::wait(std::__1::unique_lock<std::__1::mutex>&) () from /usr/lib/libc++.so.1
#4 0x00000008002e971b in std::__1::__assoc_sub_state::wait() () from /usr/lib/libc++.so.1
#5 0x0000000000205389 in std::__1::__async_assoc_state<void, std::__1::__async_func<func2(std::__1::atomic<long>&)::$_0> >::__on_zero_shared() ()
#6 0x0000000000207a22 in std::__1::__release_shared_count::operator()(std::__1::__shared_count*) ()
#7 0x00000000002044f4 in std::__1::future<void> std::__1::__make_async_assoc_state<void, std::__1::__async_func<func2(std::__1::atomic<long>&)::$_0> >(std::__1::__async_func<func2(std::__1::atomic<long>&)::$_0>&&) ()
#8 0x00000000002035ea in std::__1::future<std::__1::__invoke_of<std::__1::decay<func2(std::__1::atomic<long>&)::$_0>::type>::type> std::__1::async<func2(std::__1::atomic<long>&)::$_0>(std::__1::launch, func2(std::__1::atomic<long>&)::$_0&&) ()
#9 0x0000000000203462 in func2(std::__1::atomic<long>&) ()
#10 0x0000000000206f18 in main::$_1::operator()() const ()
#11 0x0000000000206eed in void std::__1::__async_func<main::$_1>::__execute<>(std::__1::__tuple_indices<>) ()
#12 0x0000000000206ea5 in std::__1::__async_func<main::$_1>::operator()() ()
#13 0x0000000000206df3 in std::__1::__async_assoc_state<void, std::__1::__async_func<main::$_1> >::__execute() ()
#14 0x0000000000207183 in void* std::__1::__thread_proxy<std::__1::tuple<std::__1::unique_ptr<std::__1::__thread_struct, std::__1::default_delete<std::__1::__thread_struct> >, void (std::__1::__async_assoc_state<void, std::__1::__async_func<main::$_1> >::*)(), std::__1::__async_assoc_state<void, std::__1::__async_func<main::$_1> >*> >(void*) ()
#15 0x000000080025c776 in ?? () from /lib/libthr.so.3
#16 0x0000000000000000 in ?? ()
Backtrace stopped: Cannot access memory at address 0x7fffdf9fb000
Thread 4 (LWP 100654 of process 37763):
#0 0x000000080026a66c in ?? () from /lib/libthr.so.3
#1 0x000000080025e731 in ?? () from /lib/libthr.so.3
#2 0x0000000800268388 in ?? () from /lib/libthr.so.3
#3 0x000000080032de72 in std::__1::condition_variable::wait(std::__1::unique_lock<std::__1::mutex>&) () from /usr/lib/libc++.so.1
#4 0x00000008002e971b in std::__1::__assoc_sub_state::wait() () from /usr/lib/libc++.so.1
#5 0x0000000000205389 in std::__1::__async_assoc_state<void, std::__1::__async_func<func2(std::__1::atomic<long>&)::$_0> >::__on_zero_shared() ()
#6 0x0000000000207a22 in std::__1::__release_shared_count::operator()(std::__1::__shared_count*) ()
#7 0x00000000002044f4 in std::__1::future<void> std::__1::__make_async_assoc_state<void, std::__1::__async_func<func2(std::__1::atomic<long>&)::$_0> >(std::__1::__async_func<func2(std::__1::atomic<long>&)::$_0>&&) ()
#8 0x00000000002035ea in std::__1::future<std::__1::__invoke_of<std::__1::decay<func2(std::__1::atomic<long>&)::$_0>::type>::type> std::__1::async<func2(std::__1::atomic<long>&)::$_0>(std::__1::launch, func2(std::__1::atomic<long>&)::$_0&&) ()
#9 0x0000000000203462 in func2(std::__1::atomic<long>&) ()
#10 0x0000000000206f18 in main::$_1::operator()() const ()
#11 0x0000000000206eed in void std::__1::__async_func<main::$_1>::__execute<>(std::__1::__tuple_indices<>) ()
#12 0x0000000000206ea5 in std::__1::__async_func<main::$_1>::operator()() ()
#13 0x0000000000206df3 in std::__1::__async_assoc_state<void, std::__1::__async_func<main::$_1> >::__execute() ()
#14 0x0000000000207183 in void* std::__1::__thread_proxy<std::__1::tuple<std::__1::unique_ptr<std::__1::__thread_struct, std::__1::default_delete<std::__1::__thread_struct> >, void (std::__1::__async_assoc_state<void, std::__1::__async_func<main::$_1> >::*)(), std::__1::__async_assoc_state<void, std::__1::__async_func<main::$_1> >*> >(void*) ()
#15 0x000000080025c776 in ?? () from /lib/libthr.so.3
#16 0x0000000000000000 in ?? ()
Backtrace stopped: Cannot access memory at address 0x7fffdfbfc000
Thread 3 (LWP 100653 of process 37763):
#0 0x000000080026a66c in ?? () from /lib/libthr.so.3
#1 0x000000080025e731 in ?? () from /lib/libthr.so.3
#2 0x0000000800268388 in ?? () from /lib/libthr.so.3
#3 0x000000080032de72 in std::__1::condition_variable::wait(std::__1::unique_lock<std::__1::mutex>&) () from /usr/lib/libc++.so.1
#4 0x00000008002e971b in std::__1::__assoc_sub_state::wait() () from /usr/lib/libc++.so.1
#5 0x0000000000205389 in std::__1::__async_assoc_state<void, std::__1::__async_func<func2(std::__1::atomic<long>&)::$_0> >::__on_zero_shared() ()
#6 0x0000000000207a22 in std::__1::__release_shared_count::operator()(std::__1::__shared_count*) ()
#7 0x00000000002044f4 in std::__1::future<void> std::__1::__make_async_assoc_state<void, std::__1::__async_func<func2(std::__1::atomic<long>&)::$_0> >(std::__1::__async_func<func2(std::__1::atomic<long>&)::$_0>&&) ()
#8 0x00000000002035ea in std::__1::future<std::__1::__invoke_of<std::__1::decay<func2(std::__1::atomic<long>&)::$_0>::type>::type> std::__1::async<func2(std::__1::atomic<long>&)::$_0>(std::__1::launch, func2(std::__1::atomic<long>&)::$_0&&) ()
#9 0x0000000000203462 in func2(std::__1::atomic<long>&) ()
#10 0x0000000000206f18 in main::$_1::operator()() const ()
#11 0x0000000000206eed in void std::__1::__async_func<main::$_1>::__execute<>(std::__1::__tuple_indices<>) ()
#12 0x0000000000206ea5 in std::__1::__async_func<main::$_1>::operator()() ()
#13 0x0000000000206df3 in std::__1::__async_assoc_state<void, std::__1::__async_func<main::$_1> >::__execute() ()
#14 0x0000000000207183 in void* std::__1::__thread_proxy<std::__1::tuple<std::__1::unique_ptr<std::__1::__thread_struct, std::__1::default_delete<std::__1::__thread_struct> >, void (std::__1::__async_assoc_state<void, std::__1::__async_func<main::$_1> >::*)(), std::__1::__async_assoc_state<void, std::__1::__async_func<main::$_1> >*> >(void*) ()
#15 0x000000080025c776 in ?? () from /lib/libthr.so.3
#16 0x0000000000000000 in ?? ()
Backtrace stopped: Cannot access memory at address 0x7fffdfdfd000
Thread 2 (LWP 100652 of process 37763):
#0 0x000000080026a66c in ?? () from /lib/libthr.so.3
#1 0x000000080025e731 in ?? () from /lib/libthr.so.3
#2 0x0000000800268388 in ?? () from /lib/libthr.so.3
#3 0x000000080032de72 in std::__1::condition_variable::wait(std::__1::unique_lock<std::__1::mutex>&) () from /usr/lib/libc++.so.1
#4 0x00000008002e971b in std::__1::__assoc_sub_state::wait() () from /usr/lib/libc++.so.1
#5 0x0000000000205389 in std::__1::__async_assoc_state<void, std::__1::__async_func<func2(std::__1::atomic<long>&)::$_0> >::__on_zero_shared() ()
#6 0x0000000000207a22 in std::__1::__release_shared_count::operator()(std::__1::__shared_count*) ()
#7 0x00000000002044f4 in std::__1::future<void> std::__1::__make_async_assoc_state<void, std::__1::__async_func<func2(std::__1::atomic<long>&)::$_0> >(std::__1::__async_func<func2(std::__1::atomic<long>&)::$_0>&&) ()
#8 0x00000000002035ea in std::__1::future<std::__1::__invoke_of<std::__1::decay<func2(std::__1::atomic<long>&)::$_0>::type>::type> std::__1::async<func2(std::__1::atomic<long>&)::$_0>(std::__1::launch, func2(std::__1::atomic<long>&)::$_0&&) ()
#9 0x0000000000203462 in func2(std::__1::atomic<long>&) ()
#10 0x0000000000206f18 in main::$_1::operator()() const ()
#11 0x0000000000206eed in void std::__1::__async_func<main::$_1>::__execute<>(std::__1::__tuple_indices<>) ()
#12 0x0000000000206ea5 in std::__1::__async_func<main::$_1>::operator()() ()
#13 0x0000000000206df3 in std::__1::__async_assoc_state<void, std::__1::__async_func<main::$_1> >::__execute() ()
#14 0x0000000000207183 in void* std::__1::__thread_proxy<std::__1::tuple<std::__1::unique_ptr<std::__1::__thread_struct, std::__1::default_delete<std::__1::__thread_struct> >, void (std::__1::__async_assoc_state<void, std::__1::__async_func<main::$_1> >::*)(), std::__1::__async_assoc_state<void, std::__1::__async_func<main::$_1> >*> >(void*) ()
#15 0x000000080025c776 in ?? () from /lib/libthr.so.3
#16 0x0000000000000000 in ?? ()
Backtrace stopped: Cannot access memory at address 0x7fffdfffe000
Thread 1 (LWP 100148 of process 37763):
#0 0x00000008004f984a in _nanosleep () from /lib/libc.so.7
#1 0x000000080025f17c in ?? () from /lib/libthr.so.3
#2 0x000000080045fe0b in sleep () from /lib/libc.so.7
#3 0x0000000000203b7b in main ()
It seems lots of threads got stuck on std::__1::condition_variable::wait, which is unreasonable, in the test code, there is no use of any condition at all.
Can somebody tell me, am I doing it wrong or there is a bug in the std library?
Thanks. This example didn't fully mimic the actual behavior of my program. I simplified it too much.
Now I add vector of future, this is more like it:
void func2(std::atomic_long& n)
{
std::vector<std::future<void>> rs;
for (auto i = 0L; i < 1000000000000L; ++i)
{
rs.push_back(std::async(std::launch::async, [&] {add(n);}));
}
for (auto& r : rs)
{
r.wait();
}
}
But it still got the same result:
On macOS, it was ok.
29693311 29904143 29994992 29856976 30020535 29832796
29709344 29917687 30005488 29875611 30039727 29848932
29725334 29930826 30019428 29892350 30056678 29866293
29737403 29948258 30036760 29904964 30074102 29883648
29746597 29965134 30050115 29914459 30086189 29900767
29761543 29977363 30066833 29929475 30101723 29915059
29777678 29993381 30084101 29949095 30117847 29926040
29794253 30007301 30102985 29972819 30129613 29939935
On freebsd, it froze again:
34079 29595 38239 508788 30194 41242
34079 29595 38239 509103 30194 41242
34079 29595 38239 509583 30194 41242
34079 29595 38239 509808 30194 41242
34079 29595 38239 510187 30194 41242
34079 29595 38239 510543 30194 41242
34079 29595 38239 510932 30194 41242
34079 29595 38239 511616 30194 41242
34079 29595 38239 512111 30194 41242
34079 29595 38239 512952 30194 41242
34079 29595 38239 514032 30194 41242
34079 29595 38239 514205 30194 41242
34079 29595 38239 514577 30194 41242
You are not taking into account the return value of std::async, the future returned will block any execution until the end of the task you started with std::async. This program as written, it's not performing what you expect.
In addition you are calling std::async with recursion and it's not granted it will spawn a new thread, it can manage a pool so if the pool is busy you program can freeze apparently since the loop you are doing is really long. If you want more control you can use std::thread with std::packaged_task

oracle occi ResultSet::next() core dump

#0 0x0000003d7e432925 in raise () from /lib64/libc.so.6
#1 0x0000003d7e43408d in abort () from /lib64/libc.so.6
#2 0x00007ff601e3ba55 in os::abort(bool) () from /usr/java/jdk1.7.0_67-cloudera/jre/lib/amd64/server/libjvm.so
#3 0x00007ff601fbbf87 in VMError::report_and_die() () from /usr/java/jdk1.7.0_67-cloudera/jre/lib/amd64/server/libjvm.so
#4 0x00007ff601e4096f in JVM_handle_linux_signal () from /usr/java/jdk1.7.0_67-cloudera/jre/lib/amd64/server/libjvm.so
#5 <signal handler called>
#6 0x00007ff5fe8f218e in LdiInterFromArray () from /home/zhaojuan/project/DataType/thirdparty/occi-11.2/lib/libclntsh.so.11.1
#7 0x00007ff5ff85a1eb in kpcceiyd2iyd () from /home/zhaojuan/project/DataType/thirdparty/occi-11.2/lib/libclntsh.so.11.1
#8 0x00007ff600138c1d in ttccfpg () from /home/zhaojuan/project/DataType/thirdparty/occi-11.2/lib/libclntsh.so.11.1
#9 0x00007ff600136e90 in ttcfour () from /home/zhaojuan/project/DataType/thirdparty/occi-11.2/lib/libclntsh.so.11.1
#10 0x00007ff5fe5c45f3 in kpufcpf () from /home/zhaojuan/project/DataType/thirdparty/occi-11.2/lib/libclntsh.so.11.1
#11 0x00007ff5fe5c2872 in kpufch0 () from /home/zhaojuan/project/DataType/thirdparty/occi-11.2/lib/libclntsh.so.11.1
#12 0x00007ff5fe5c110f in kpufch () from /home/zhaojuan/project/DataType/thirdparty/occi-11.2/lib/libclntsh.so.11.1
#13 0x00007ff5fe556a03 in OCIStmtFetch () from /home/zhaojuan/project/DataType/thirdparty/occi-11.2/lib/libclntsh.so.11.1
#14 0x00007ff600a29b33 in oracle::occi::ResultSetImpl::next(unsigned int) () from /home/zhaojuan/project/DataType/thirdparty/occi-11.2/lib/libocci.so.11.1
#15 0x0000000000c6f481 in xcloud::xos::OracleLoader::RunLoadMain (this=0x78e6680) at /home/zhaojuan/project/DataType/be/src/exec_xos/OracleLoader.cpp:366
#16 0x0000000000c70f49 in xcloud::xos::OracleLoaderThread (This=<value optimized out>)
at /home/zhaojuan/project/DataType/be/src/exec_xos/OracleLoader.cpp:43
#17 0x0000003d7e8079d1 in start_thread () from /lib64/libpthread.so.0
#18 0x0000003d7e4e8b6d in clone () from /lib64/libc.so.6
hi , I met a occi problem, I want to get interval value from oracle, but it was core dump ,why?
the simplest code is
if (ttype == oracle::occi::OCCI_SQLT_INTERVAL_YM) {
LOG(INFO) << "set YM buffer";
m_res->setDataBuffer(i + 1, m_colBuf[i], ttype, 5, &(m_resultInfos[i].fieldLens[0]),
&(m_resultInfos[i].fieldFlags[0]), &(m_resultInfos[i].fieldRCs[0]));
} else if (ttype == oracle::occi::OCCI_SQLT_INTERVAL_DS) {
m_res->setDataBuffer(i + 1, m_colBuf[i], ttype, 11, &(m_resultInfos[i].fieldLens[0]),
&(m_resultInfos[i].fieldFlags[0]), &(m_resultInfos[i].fieldRCs[0]));
}
m_res is a type of oracle::occi::ResultSet*
m_colBuf[i] is alloc(colWidth[i] * fetchsize)
and it was crashed at:
if (0 == m_res->next(m_fetchSize)) {
LOG(INFO) << "Oracle Fetch finished!";
break;
}

Qt Application stuck waiting for a wake event from the system

I am in a bit of a pickle.
My application has one main window (inherits from QMainWindow). The main window is parent to a QTabWidget, which acts as a sort of dialog that shows up when the user clicks a toolbar button on the main window, and hides when its 'Close' button is clicked. In addition, the main window has another toolbar button, which when clicked, calls exec() on a QDialog. While developing the app, I have noticed that once every 40 times or so, clicking one of the two buttons I have mentioned causes an empty widget to appear, but instead of the intended view being drawn, everything freezes. When I click the 'Close' button on the main window, my OS tells me that the application has stopped responding. There is never any way to recover from crashes like this, and I am usually forced to kill the app and restart.
The vexing thing about all this is that I cannot reproduce the crashes at will. They are impossible to predict, and often catch me off-guard.
I used gdb to attach to a frozen instance, and got the following back trace:
#0 pthread_cond_wait##GLIBC_2.3.2 ()
at ../nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_wait.S:185
#1 0x00007f1ba3bf1b03 in QWaitCondition::wait(QMutex*, unsigned long) ()
from /opt/Qt/5.4/gcc_64/lib/libQt5Core.so.5
#2 0x00007f1ba3bea277 in QReadWriteLock::lockForRead() ()
from /opt/Qt/5.4/gcc_64/lib/libQt5Core.so.5
#3 0x00007f1b9bf5ee4e in ?? () from /opt/Qt/5.4/gcc_64/plugins/platforms/../../lib/libQt5DBus.so.5
#4 0x00007f1b9bf61d71 in ?? () from /opt/Qt/5.4/gcc_64/plugins/platforms/../../lib/libQt5DBus.so.5
#5 0x00007f1b9bf64e54 in ?? () from /opt/Qt/5.4/gcc_64/plugins/platforms/../../lib/libQt5DBus.so.5
#6 0x00007f1b904159d6 in dbus_connection_dispatch () from /lib/x86_64-linux-gnu/libdbus-1.so.3
#7 0x00007f1b9bf579f5 in ?? () from /opt/Qt/5.4/gcc_64/plugins/platforms/../../lib/libQt5DBus.so.5
#8 0x00007f1b9bfa78f5 in ?? () from /opt/Qt/5.4/gcc_64/plugins/platforms/../../lib/libQt5DBus.so.5
#9 0x00007f1ba3e5a326 in QObject::event(QEvent*) () from /opt/Qt/5.4/gcc_64/lib/libQt5Core.so.5
#10 0x00007f1ba510b8f4 in QApplicationPrivate::notify_helper(QObject*, QEvent*) ()
from /opt/Qt/5.4/gcc_64/lib/libQt5Widgets.so.5
#11 0x00007f1ba510f506 in QApplication::notify(QObject*, QEvent*) ()
from /opt/Qt/5.4/gcc_64/lib/libQt5Widgets.so.5
#12 0x00007f1ba3e25c84 in QCoreApplication::notifyInternal(QObject*, QEvent*) ()
from /opt/Qt/5.4/gcc_64/lib/libQt5Core.so.5
#13 0x00007f1ba3e28868 in QCoreApplicationPrivate::sendPostedEvents(QObject*, int, QThreadData*) ()
from /opt/Qt/5.4/gcc_64/lib/libQt5Core.so.5
#14 0x00007f1ba3e80123 in ?? () from /opt/Qt/5.4/gcc_64/lib/libQt5Core.so.5
#15 0x00007f1ba283be04 in g_main_context_dispatch () from /lib/x86_64-linux-gnu/libglib-2.0.so.0
#16 0x00007f1ba283c048 in ?? () from /lib/x86_64-linux-gnu/libglib-2.0.so.0
#17 0x00007f1ba283c0ec in g_main_context_iteration () from /lib/x86_64-linux-gnu/libglib-2.0.so.0
#18 0x00007f1ba3e80554 in QEventDispatcherGlib::processEvents(QFlags<QEventLoop::ProcessEventsFlag>)
() from /opt/Qt/5.4/gcc_64/lib/libQt5Core.so.5
#19 0x00007f1ba3e23eab in QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) ()
from /opt/Qt/5.4/gcc_64/lib/libQt5Core.so.5
#20 0x00007f1ba530a2ed in QDialog::exec() () from /opt/Qt/5.4/gcc_64/lib/libQt5Widgets.so.5
#21 0x0000000000425fe4 in MainWindow::AddNewDownload() ()
#22 0x00007f1ba3e57e7a in QMetaObject::activate(QObject*, int, int, void**) ()
from /opt/Qt/5.4/gcc_64/lib/libQt5Core.so.5
#23 0x00007f1ba50fee52 in QAction::triggered(bool) () from /opt/Qt/5.4/gcc_64/lib/libQt5Widgets.so.5
#24 0x00007f1ba5100c77 in QAction::activate(QAction::ActionEvent) ()
from /opt/Qt/5.4/gcc_64/lib/libQt5Widgets.so.5
#25 0x00007f1ba520b0b5 in ?? () from /opt/Qt/5.4/gcc_64/lib/libQt5Widgets.so.5
#26 0x00007f1ba520b374 in QAbstractButton::mouseReleaseEvent(QMouseEvent*) ()
from /opt/Qt/5.4/gcc_64/lib/libQt5Widgets.so.5
#27 0x00007f1ba52cf89a in QToolButton::mouseReleaseEvent(QMouseEvent*) ()
from /opt/Qt/5.4/gcc_64/lib/libQt5Widgets.so.5
#28 0x00007f1ba514723c in QWidget::event(QEvent*) () from /opt/Qt/5.4/gcc_64/lib/libQt5Widgets.so.5
#29 0x00007f1ba52d0730 in QToolButton::event(QEvent*) ()
from /opt/Qt/5.4/gcc_64/lib/libQt5Widgets.so.5
#30 0x00007f1ba510b8f4 in QApplicationPrivate::notify_helper(QObject*, QEvent*) ()
from /opt/Qt/5.4/gcc_64/lib/libQt5Widgets.so.5
#31 0x00007f1ba510f071 in QApplication::notify(QObject*, QEvent*) ()
from /opt/Qt/5.4/gcc_64/lib/libQt5Widgets.so.5
#32 0x00007f1ba3e25c84 in QCoreApplication::notifyInternal(QObject*, QEvent*) ()
from /opt/Qt/5.4/gcc_64/lib/libQt5Core.so.5
#33 0x00007f1ba510df88 in QApplicationPrivate::sendMouseEvent(QWidget*, QMouseEvent*, QWidget*, QWidget*, QWidget**, QPointer<QWidget>&, bool) () from /opt/Qt/5.4/gcc_64/lib/libQt5Widgets.so.5
#34 0x00007f1ba5162387 in ?? () from /opt/Qt/5.4/gcc_64/lib/libQt5Widgets.so.5
#35 0x00007f1ba5164e78 in ?? () from /opt/Qt/5.4/gcc_64/lib/libQt5Widgets.so.5
---Type <return> to continue, or q <return> to quit---
It appears that my app is stuck waiting to be woken up when a certain condition is met. The presence of dbus in the back trace suggests that it was trying to talk to another process, which I am guessing is a GUI-related process. I however do not know why the wait condition is met 98% of the time, but fails 2% of the time. When using strace, I was able to find that the system call that blocked is:
futex(0x7f403c00690c, FUTEX_WAIT_PRIVATE, 1, NULL)
I am not using QThreads or mutexes in my code, so I am guessing this problem is Qt-internal. Does anyone with knowledge of low-level workings of Qt know what is happening?

Poco ParallelSocketAcceptor crash

I use Poco-libraries parallel socket acceptor in my application and it sometimes crashes. Here is the backtrace of my application:
Program terminated with signal SIGABRT, Aborted.
#0 0x00007f9ed30ee107 in __GI_raise (sig=sig#entry=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:56
56 ../nptl/sysdeps/unix/sysv/linux/raise.c: No such file or directory.
(gdb) bt
#0 0x00007f9ed30ee107 in __GI_raise (sig=sig#entry=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:56
#1 0x00007f9ed30ef4e8 in __GI_abort () at abort.c:89
#2 0x00007f9ed312c044 in __libc_message (do_abort=do_abort#entry=1,
fmt=fmt#entry=0x7f9ed321ec60 "*** Error in `%s': %s: 0x%s ***\n") at ../sysdeps/posix/libc_fatal.c:175
#3 0x00007f9ed313181e in malloc_printerr (action=1, str=0x7f9ed321f000 "malloc(): memory corruption (fast)",
ptr=<optimized out>) at malloc.c:4996
#4 0x00007f9ed3133bbb in _int_malloc (av=0x7f9ecc000020, bytes=32) at malloc.c:3359
#5 0x00007f9ed3134eb0 in __GI___libc_malloc (bytes=32) at malloc.c:2891
#6 0x00007f9ed39d82e8 in operator new(unsigned long) () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#7 0x0000000000471058 in Poco::Net::ParallelSocketAcceptor<BFSTcpServiceHandler, Poco::Net::SocketReactor>::createServiceHandler (this=0x7f9ed0e17d70, socket=...) at /usr/local/include/Poco/Net/ParallelSocketAcceptor.h:172
#8 0x00000000004709d2 in Poco::Net::ParallelSocketAcceptor<BFSTcpServiceHandler, Poco::Net::SocketReactor>::onAccept
(this=0x7f9ed0e17d70, pNotification=0x7f9ecc0009c0) at /usr/local/include/Poco/Net/ParallelSocketAcceptor.h:160
#9 0x0000000000472bfe in Poco::Observer<Poco::Net::ParallelSocketAcceptor<BFSTcpServiceHandler, Poco::Net::SocketReactor>, Poco::Net::ReadableNotification>::notify (this=0x7f9ecc001d20, pNf=0x7f9ecc0009c0)
at /usr/local/include/Poco/Observer.h:86
#10 0x00007f9ed4709c4b in Poco::NotificationCenter::postNotification(Poco::AutoPtr<Poco::Notification>) ()
from /usr/local/lib/libPocoFoundation.so.30
#11 0x00007f9ed43c6630 in Poco::Net::SocketNotifier::dispatch(Poco::Net::SocketNotification*) ()
from /usr/local/lib/libPocoNet.so.30
#12 0x00007f9ed43c38a4 in Poco::Net::SocketReactor::dispatch(Poco::AutoPtr<Poco::Net::SocketNotifier>&, Poco::Net::SocketNotification*) () from /usr/local/lib/libPocoNet.so.30
#13 0x00007f9ed43c3d1b in Poco::Net::SocketReactor::dispatch(Poco::Net::Socket const&, Poco::Net::SocketNotification*)
() from /usr/local/lib/libPocoNet.so.30
#14 0x00007f9ed43c4910 in Poco::Net::SocketReactor::run() () from /usr/local/lib/libPocoNet.so.30
#15 0x000000000046a8dc in BFSTcpServer::run () at src/BFSTcpServer.cpp:69
#16 0x0000000000459c1b in std::_Bind_simple<void (*())()>::_M_invoke<>(std::_Index_tuple<>) (this=0x1ee8d38)
at /usr/include/c++/4.9/functional:1700
---Type <return> to continue, or q <return> to quit---
#17 0x0000000000459b63 in std::_Bind_simple<void (*())()>::operator()() (this=0x1ee8d38)
at /usr/include/c++/4.9/functional:1688
#18 0x0000000000459ae0 in std::thread::_Impl<std::_Bind_simple<void (*())()> >::_M_run() (this=0x1ee8d20)
at /usr/include/c++/4.9/thread:115
#19 0x00007f9ed3a2f970 in ?? () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#20 0x00007f9ed4eaa0a4 in start_thread (arg=0x7f9ed0e18700) at pthread_create.c:309
#21 0x00007f9ed319eccd in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:111
I use the socket acceptor like this:
...
ServerSocket serverSocket(port);
reactor = new SocketReactor();
ParallelSocketAcceptor<BFSTcpServiceHandler,SocketReactor> acceptor(serverSocket, *reactor);
reactor->run();
...
And my servicehandler class is as follows:
class BFSTcpServiceHandler {
Poco::Net::StreamSocket socket;
Poco::Net::SocketReactor& reactor;
...
void onReadable(const Poco::AutoPtr<Poco::Net::ReadableNotification>& pNf);
...
public:
BFSTcpServiceHandler(Poco::Net::StreamSocket& _socket,
Poco::Net::SocketReactor& _reactor);
virtual ~BFSTcpServiceHandler();
};
//And implementation:
BFSTcpServiceHandler::BFSTcpServiceHandler(StreamSocket& _socket,
SocketReactor& _reactor): socket(_socket),reactor(_reactor) {
//Register Callbacks
reactor.addEventHandler(socket, NObserver<BFSTcpServiceHandler,
ReadableNotification>(*this, &BFSTcpServiceHandler::onReadable));
}
BFSTcpServiceHandler::~BFSTcpServiceHandler() {
//Unregister Callbacks
reactor.removeEventHandler(socket, NObserver<BFSTcpServiceHandler,
ReadableNotification>(*this, &BFSTcpServiceHandler::onReadable));
//Close socket
try {
socket.shutdown();
socket.close();
}catch(Exception &e){
LOG(ERROR)<<"ERROR IN CLOSING CONNECTION";
}
}
void BFSTcpServiceHandler::onReadable(
const Poco::AutoPtr<Poco::Net::ReadableNotification>& pNf) {
...
int read = socket.receiveBytes(_packet,sizeof(reqPacket.opCode));
...
//connection is served just close it!
delete this;
}
I am not sure if this is a bug in poco or my program. Either way, I will highly appreciate any comment or help. You can take a look at the full source of mine here:
https://github.com/bshafiee/BFS/blob/master/src/BFSTcpServer.cpp#L57
https://github.com/bshafiee/BFS/blob/master/src/BFSTcpServiceHandler.cpp#L65
Compiler Info:
gcc (Debian 4.9.1-19) 4.9.1
Poco Verision:
1.6.0 (2014-12-22)