c++ - Poco ParallelSocketAcceptor crash -
i use poco-libraries parallel socket acceptor in application , crashes. here backtrace of application:
program terminated signal sigabrt, aborted. #0 0x00007f9ed30ee107 in __gi_raise (sig=sig@entry=6) @ ../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) @ ../nptl/sysdeps/unix/sysv/linux/raise.c:56 #1 0x00007f9ed30ef4e8 in __gi_abort () @ 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") @ ../sysdeps/posix/libc_fatal.c:175 #3 0x00007f9ed313181e in malloc_printerr (action=1, str=0x7f9ed321f000 "malloc(): memory corruption (fast)", ptr=<optimized out>) @ malloc.c:4996 #4 0x00007f9ed3133bbb in _int_malloc (av=0x7f9ecc000020, bytes=32) @ malloc.c:3359 #5 0x00007f9ed3134eb0 in __gi___libc_malloc (bytes=32) @ malloc.c:2891 #6 0x00007f9ed39d82e8 in operator new(unsigned long) () /usr/lib/x86_64-linux-gnu/libstdc++.so.6 #7 0x0000000000471058 in poco::net::parallelsocketacceptor<bfstcpservicehandler, poco::net::socketreactor>::createservicehandler (this=0x7f9ed0e17d70, socket=...) @ /usr/local/include/poco/net/parallelsocketacceptor.h:172 #8 0x00000000004709d2 in poco::net::parallelsocketacceptor<bfstcpservicehandler, poco::net::socketreactor>::onaccept (this=0x7f9ed0e17d70, pnotification=0x7f9ecc0009c0) @ /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) @ /usr/local/include/poco/observer.h:86 #10 0x00007f9ed4709c4b in poco::notificationcenter::postnotification(poco::autoptr<poco::notification>) () /usr/local/lib/libpocofoundation.so.30 #11 0x00007f9ed43c6630 in poco::net::socketnotifier::dispatch(poco::net::socketnotification*) () /usr/local/lib/libpoconet.so.30 #12 0x00007f9ed43c38a4 in poco::net::socketreactor::dispatch(poco::autoptr<poco::net::socketnotifier>&, poco::net::socketnotification*) () /usr/local/lib/libpoconet.so.30 #13 0x00007f9ed43c3d1b in poco::net::socketreactor::dispatch(poco::net::socket const&, poco::net::socketnotification*) () /usr/local/lib/libpoconet.so.30 #14 0x00007f9ed43c4910 in poco::net::socketreactor::run() () /usr/local/lib/libpoconet.so.30 #15 0x000000000046a8dc in bfstcpserver::run () @ src/bfstcpserver.cpp:69 #16 0x0000000000459c1b in std::_bind_simple<void (*())()>::_m_invoke<>(std::_index_tuple<>) (this=0x1ee8d38) @ /usr/include/c++/4.9/functional:1700 ---type <return> continue, or q <return> quit--- #17 0x0000000000459b63 in std::_bind_simple<void (*())()>::operator()() (this=0x1ee8d38) @ /usr/include/c++/4.9/functional:1688 #18 0x0000000000459ae0 in std::thread::_impl<std::_bind_simple<void (*())()> >::_m_run() (this=0x1ee8d20) @ /usr/include/c++/4.9/thread:115 #19 0x00007f9ed3a2f970 in ?? () /usr/lib/x86_64-linux-gnu/libstdc++.so.6 #20 0x00007f9ed4eaa0a4 in start_thread (arg=0x7f9ed0e18700) @ pthread_create.c:309 #21 0x00007f9ed319eccd in clone () @ ../sysdeps/unix/sysv/linux/x86_64/clone.s:111
i use socket acceptor this:
... serversocket serversocket(port); reactor = new socketreactor(); parallelsocketacceptor<bfstcpservicehandler,socketreactor> acceptor(serversocket, *reactor); reactor->run(); ...
and servicehandler class 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 served close it! delete this; }
i not sure if bug in poco or program. either way, highly appreciate comment or help. can take @ 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)
Comments
Post a Comment