Closed Erkan-Yilmaz closed 10 years ago
Ok, good report. We need to have some mutual exclusion between the libtorrent::session (ses) deletion (twister.cpp:729) and command execution (like twister.cpp:433 from getinfo).
In other words: we tried deleting the libtorrent object while it was still being used by getinfo RPC.
I think the proper fix is not a simple mutex on "ses" usage: we don't want an exclusion preventing simultaneous libtorrent access as it would hurt performance. We need either a sort or read-write locker or a pointer container with usage counter. I'm not sure what good boost templates are provided for us to use in this case.
commited fix. please check!
a. twister was running for >4h b. terminate twisterd daemon (from twister-html, network options) c. and got:
Program received signal SIGSEGV, Segmentation fault. [Switching to Thread 0xae6f8b40 (LWP 5501)] push (h=0xb4304c98, this=0xb290cb08) at /usr/include/boost/asio/detail/op_queue.hpp:110 110 op_queueaccess::next(back, h);
below are debugger output, last log lines, peers at one point during session:
debugger
[Thread 0xb42ffb40 (LWP 5512) exited] [Thread 0xa8eedb40 (LWP 5513) exited]
Program received signal SIGSEGV, Segmentation fault. [Switching to Thread 0xae6f8b40 (LWP 5501)] push (h=0xb4304c98, this=0xb290cb08) at /usr/include/boost/asio/detail/op_queue.hpp:110 110 op_queueaccess::next(back, h);
backtrace
0 push (h=0xb4304c98, this=0xb290cb08) at /usr/include/boost/asio/detail/op_queue.hpp:110
1 boost::asio::detail::task_io_service::do_dispatch (this=this@entry=0xb290cac0, op=op@entry=0xb4304c98)
2 0x081ad4b6 in boost::asio::detail::task_io_service::dispatch<boost::_bi::bind_t<void, void ()(libtorrent::session_status, bool, libtorrent::condition_variable, boost::asio::detail::posix_mutex, boost::function<libtorrent::session_status ()>), boost::_bi::list5boost::_bi::value<libtorrent::session_status, boost::_bi::value<bool>, boost::_bi::valuelibtorrent::condition_variable, boost::_bi::valueboost::asio::detail::posix_mutex, boost::_bi::value<boost::function<libtorrent::session_status ()> > > > >(boost::_bi::bind_t<void, void ()(libtorrent::session_status, bool, libtorrent::condition_variable, boost::asio::detail::posix_mutex, boost::function<libtorrent::session_status ()>), boost::_bi::list5boost::_bi::value<libtorrent::session_status, boost::_bi::value<bool>, boost::_bi::valuelibtorrent::condition_variable, boost::_bi::valueboost::asio::detail::posix_mutex, boost::_bi::value<boost::function<libtorrent::session_status ()> > > >&) (this=0xb290cac0, handler=...) at /usr/include/boost/asio/detail/impl/task_io_service.hpp:50
3 0x0819ce9a in dispatch<boost::_bi::bind_t<void, void ()(libtorrent::session_status, bool, libtorrent::condition_variable, boost::asio::detail::posix_mutex, boost::function<libtorrent::session_status()>), boost::_bi::list5boost::_bi::value<libtorrent::session_status, boost::_bi::value<bool>, boost::_bi::valuelibtorrent::condition_variable, boost::_bi::valueboost::asio::detail::posix_mutex*, boost::_bi::valueboost::function<libtorrent::session_status() > > > > (this=0xb290d1f4, handler=...) at /usr/include/boost/asio/impl/io_service.hpp:91
4 libtorrent::session::status (this=0xb290ae38) at libtorrent/src/session.cpp:768
5 0x083d4eeb in getDhtNodes (dht_global_nodes=dht_global_nodes@entry=0xae6f7ad0) at src/twister.cpp:433
6 0x0838f8d1 in getinfo (params=..., fHelp=false) at src/rpcwallet.cpp:87
7 0x083586f3 in CRPCTable::execute (this=this@entry=0x860f1c0, strMethod=..., params=...) at src/bitcoinrpc.cpp:1128
8 0x0835cc68 in ServiceConnection (conn=conn@entry=0xa85b15d8) at src/bitcoinrpc.cpp:1080
9 0x0835dee8 in RPCAcceptHandler<boost::asio::ip::tcp, boost::asio::socket_acceptor_service > (acceptor=..., context=...,
10 0x08366e5d in operator()<void ()(boost::shared_ptr<boost::asio::basic_socket_acceptor >, boost::asio::ssl::context&, bool, AcceptedConnection , const boost::system::error_code&), boost::_bi::list1<const boost::system::error_code&> > (
11 operator()boost::system::error_code (a1=..., this=0xae6f81d0) at /usr/include/boost/bind/bind_template.hpp:47
12 operator() (this=0xae6f81d0) at /usr/include/boost/asio/detail/bind_handler.hpp:47
13 asio_handler_invoke<boost::asio::detail::binder1<boost::_bi::bind_t<void, void ()(boost::shared_ptr<boost::asio::basic_socketacceptor >, boost::asio::ssl::context&, bool, AcceptedConnection , boost::system::error_code const&), boost::_bi::list5boost::_bi::value<boost::shared_ptr<boost::asio::basic_socket_acceptor >, boost::reference_wrapperboost::asio::ssl::context, boost::_bi::value, boost::bi::value<AcceptedConnectionImpl >, boost::arg<1> ( )()> >, boost::system::error_code> > (
14 invoke<boost::asio::detail::binder1<boost::_bi::bind_t<void, void ()(boost::shared_ptr<boost::asio::basic_socketacceptor >, boost::asio::ssl::context&, bool, AcceptedConnection , boost::system::error_code const&), boost::_bi::list5boost::_bi::value<boost::shared_ptr<boost::asio::basic_socket_acceptor >, boost::reference_wrapperboost::asio::ssl::context, boost::_bi::value, boost::bi::value<AcceptedConnectionImpl >, boost::arg<1> (_)()> >, boost::system::error_code>, boost::_bi::bindt<void, void ()(boost::shared_ptrboost::asio::basic_socket_acceptor, boost::asio::ssl::context&, bool, AcceptedConnection , boost::system::error_code const&), boost::_bi::list5<boost::_bi:---Type to continue, or q to quit---
:valueboost::shared_ptr<boost::asio::basic_socket_acceptor >, boost::reference_wrapperboost::asio::ssl::context, boost::_bi::value, boost::bi::value<AcceptedConnectionImpl >, boost::arg<1> (_)()> > > (context=..., function=...)
at /usr/include/boost/asio/detail/handler_invoke_helpers.hpp:37
15 boost::asio::detail::reactive_socket_accept_op<boost::asio::basic_socket<boost::asio::ip::tcp, boost::asio::stream_socket_service >, boost::asio::ip::tcp, boost::_bi::bind_t<void, void ()(boost::shared_ptr<boost::asio::basic_socket_acceptor<boost::asio::ip::tcp, boost::asio::socket_acceptorservice > >, boost::asio::ssl::context&, bool, AcceptedConnection , boost::system::error_code const&), boost::_bi::list5<boost::_bi::value<boost::shared_ptr<boost::asio::basic_socket_acceptor<boost::asio::ip::tcp, boost::asio::socket_acceptor_service > > >, boost::reference_wrapperboost::asio::ssl::context, boost::_bi::value, boost::bi::value<AcceptedConnectionImpl >, boost::arg<1> ( )()> > >::do_complete (owner=0x8ff11d0, base=0x8ff2088) at /usr/include/boost/asio/detail/reactive_socket_accept_op.hpp:123
16 0x0807c2ad in complete (bytes_transferred=, ec=..., owner=..., this=0x8ff1a60)
17 boost::asio::detail::task_io_service::do_run_one (this=this@entry=0x8ff11d0, lock=..., this_thread=..., ec=...)
18 0x080807e0 in boost::asio::detail::task_io_service::run (this=0x8ff11d0, ec=...) at /usr/include/boost/asio/detail/impl/task_io_service.ipp:153
19 0x0808096c in boost::asio::io_service::run (this=0x8785f90) at /usr/include/boost/asio/impl/io_service.ipp:59
20 0xb7f1e683 in ?? () from /usr/lib/i386-linux-gnu/libboost_thread.so.1.54.0
21 0xb7961f70 in start_thread (arg=0xae6f8b40) at pthread_create.c:312
22 0xb774b70e in clone () at ../sysdeps/unix/sysv/linux/i386/clone.S:129
where
0 push (h=0xb4304c98, this=0xb290cb08) at /usr/include/boost/asio/detail/op_queue.hpp:110
1 boost::asio::detail::task_io_service::do_dispatch (this=this@entry=0xb290cac0, op=op@entry=0xb4304c98)
2 0x081ad4b6 in boost::asio::detail::task_io_service::dispatch<boost::_bi::bind_t<void, void ()(libtorrent::session_status, bool, libtorrent::condition_variable, boost::asio::detail::posix_mutex, boost::function<libtorrent::session_status ()>), boost::_bi::list5boost::_bi::value<libtorrent::session_status, boost::_bi::value<bool>, boost::_bi::valuelibtorrent::condition_variable, boost::_bi::valueboost::asio::detail::posix_mutex, boost::_bi::value<boost::function<libtorrent::session_status ()> > > > >(boost::_bi::bind_t<void, void ()(libtorrent::session_status, bool, libtorrent::condition_variable, boost::asio::detail::posix_mutex, boost::function<libtorrent::session_status ()>), boost::_bi::list5boost::_bi::value<libtorrent::session_status, boost::_bi::value<bool>, boost::_bi::valuelibtorrent::condition_variable, boost::_bi::valueboost::asio::detail::posix_mutex, boost::_bi::value<boost::function<libtorrent::session_status ()> > > >&) (this=0xb290cac0, handler=...) at /usr/include/boost/asio/detail/impl/task_io_service.hpp:50
3 0x0819ce9a in dispatch<boost::_bi::bind_t<void, void ()(libtorrent::session_status, bool, libtorrent::condition_variable, boost::asio::detail::posix_mutex, boost::function<libtorrent::session_status()>), boost::_bi::list5boost::_bi::value<libtorrent::session_status, boost::_bi::value<bool>, boost::_bi::valuelibtorrent::condition_variable, boost::_bi::valueboost::asio::detail::posix_mutex*, boost::_bi::valueboost::function<libtorrent::session_status() > > > > (this=0xb290d1f4, handler=...) at /usr/include/boost/asio/impl/io_service.hpp:91
4 libtorrent::session::status (this=0xb290ae38) at libtorrent/src/session.cpp:768
5 0x083d4eeb in getDhtNodes (dht_global_nodes=dht_global_nodes@entry=0xae6f7ad0) at src/twister.cpp:433
6 0x0838f8d1 in getinfo (params=..., fHelp=false) at src/rpcwallet.cpp:87
7 0x083586f3 in CRPCTable::execute (this=this@entry=0x860f1c0, strMethod=..., params=...) at src/bitcoinrpc.cpp:1128
8 0x0835cc68 in ServiceConnection (conn=conn@entry=0xa85b15d8) at src/bitcoinrpc.cpp:1080
9 0x0835dee8 in RPCAcceptHandler<boost::asio::ip::tcp, boost::asio::socket_acceptor_service > (acceptor=..., context=...,
10 0x08366e5d in operator()<void ()(boost::shared_ptr<boost::asio::basic_socket_acceptor >, boost::asio::ssl::context&, bool, AcceptedConnection , const boost::system::error_code&), boost::_bi::list1<const boost::system::error_code&> > (
11 operator()boost::system::error_code (a1=..., this=0xae6f81d0) at /usr/include/boost/bind/bind_template.hpp:47
12 operator() (this=0xae6f81d0) at /usr/include/boost/asio/detail/bind_handler.hpp:47
13 asio_handler_invoke<boost::asio::detail::binder1<boost::_bi::bind_t<void, void ()(boost::shared_ptr<boost::asio::basic_socketacceptor >, boost::asio::ssl::context&, bool, AcceptedConnection , boost::system::error_code const&), boost::_bi::list5boost::_bi::value<boost::shared_ptr<boost::asio::basic_socket_acceptor >, boost::reference_wrapperboost::asio::ssl::context, boost::_bi::value, boost::bi::value<AcceptedConnectionImpl >, boost::arg<1> ( )()> >, boost::system::error_code> > (
14 invoke<boost::asio::detail::binder1<boost::_bi::bind_t<void, void ()(boost::shared_ptr<boost::asio::basic_socketacceptor >, boost::asio::ssl::context&, bool, AcceptedConnection , boost::system::error_code const&), boost::_bi::list5boost::_bi::value<boost::shared_ptr<boost::asio::basic_socket_acceptor >, boost::reference_wrapperboost::asio::ssl::context, boost::_bi::value, boost::bi::value<AcceptedConnectionImpl >, boost::arg<1> (_)()> >, boost::system::error_code>, boost::_bi::bindt<void, void ()(boost::shared_ptrboost::asio::basic_socket_acceptor, boost::asio::ssl::context&, bool, AcceptedConnection , boost::system::error_code const&), boost::_bi::list5<boost::_bi:---Type to continue, or q to quit---
:valueboost::shared_ptr<boost::asio::basic_socket_acceptor >, boost::reference_wrapperboost::asio::ssl::context, boost::_bi::value, boost::bi::value<AcceptedConnectionImpl >, boost::arg<1> (_)()> > > (context=..., function=...)
at /usr/include/boost/asio/detail/handler_invoke_helpers.hpp:37
15 boost::asio::detail::reactive_socket_accept_op<boost::asio::basic_socket<boost::asio::ip::tcp, boost::asio::stream_socket_service >, boost::asio::ip::tcp, boost::_bi::bind_t<void, void ()(boost::shared_ptr<boost::asio::basic_socket_acceptor<boost::asio::ip::tcp, boost::asio::socket_acceptorservice > >, boost::asio::ssl::context&, bool, AcceptedConnection , boost::system::error_code const&), boost::_bi::list5<boost::_bi::value<boost::shared_ptr<boost::asio::basic_socket_acceptor<boost::asio::ip::tcp, boost::asio::socket_acceptor_service > > >, boost::reference_wrapperboost::asio::ssl::context, boost::_bi::value, boost::bi::value<AcceptedConnectionImpl >, boost::arg<1> ( )()> > >::do_complete (owner=0x8ff11d0, base=0x8ff2088) at /usr/include/boost/asio/detail/reactive_socket_accept_op.hpp:123
16 0x0807c2ad in complete (bytes_transferred=, ec=..., owner=..., this=0x8ff1a60)
17 boost::asio::detail::task_io_service::do_run_one (this=this@entry=0x8ff11d0, lock=..., this_thread=..., ec=...)
18 0x080807e0 in boost::asio::detail::task_io_service::run (this=0x8ff11d0, ec=...) at /usr/include/boost/asio/detail/impl/task_io_service.ipp:153
19 0x0808096c in boost::asio::io_service::run (this=0x8785f90) at /usr/include/boost/asio/impl/io_service.ipp:59
20 0xb7f1e683 in ?? () from /usr/lib/i386-linux-gnu/libboost_thread.so.1.54.0
21 0xb7961f70 in start_thread (arg=0xae6f8b40) at pthread_create.c:312
22 0xb774b70e in clone () at ../sysdeps/unix/sysv/linux/i386/clone.S:129
thread apply all bt
Thread 28 (Thread 0xa8104b40 (LWP 5514)):
0 0xb7fdd424 in __kernel_vsyscall ()
1 0xb7965d4b in pthread_cond_wait@@GLIBC_2.3.2 () at ../nptl/sysdeps/unix/sysv/linux/i386/i686/../i486/pthread_cond_wait.S:187
2 0x0841eb6c in leveldb::(anonymous namespace)::PosixEnv::BGThreadWrapper(void*) ()
3 0xb7961f70 in start_thread (arg=0xa8104b40) at pthread_create.c:312
4 0xb774b70e in clone () at ../sysdeps/unix/sysv/linux/i386/clone.S:129
Thread 21 (Thread 0xab6f2b40 (LWP 5507)):
0 0xb7fdd424 in __kernel_vsyscall ()
1 0xb7965d4b in pthread_cond_wait@@GLIBC_2.3.2 () at ../nptl/sysdeps/unix/sysv/linux/i386/i686/../i486/pthread_cond_wait.S:187
2 0x0807c246 in waitboost::asio::detail::scoped_lock (lock=..., this=0xab6f22a8)
3 boost::asio::detail::task_io_service::do_run_one (this=this@entry=0x8ff11d0, lock=..., this_thread=..., ec=...)
4 0x080807e0 in boost::asio::detail::task_io_service::run (this=0x8ff11d0, ec=...) at /usr/include/boost/asio/detail/impl/task_io_service.ipp:153
5 0x0808096c in boost::asio::io_service::run (this=0x8785f90) at /usr/include/boost/asio/impl/io_service.ipp:59
6 0xb7f1e683 in ?? () from /usr/lib/i386-linux-gnu/libboost_thread.so.1.54.0
7 0xb7961f70 in start_thread (arg=0xab6f2b40) at pthread_create.c:312
8 0xb774b70e in clone () at ../sysdeps/unix/sysv/linux/i386/clone.S:129
Thread 20 (Thread 0xabef3b40 (LWP 5506)):
0 0xb7fdd424 in __kernel_vsyscall ()
1 0xb7969228 in recvmsg () at ../sysdeps/unix/sysv/linux/i386/socket.S:95
2 0x080786f5 in boost::asio::detail::socket_ops::recv (s=77, bufs=0xabef2d94, count=1, flags=0, ec=...)
3 0x0807975e in boost::asio::detail::socket_ops::sync_recv (s=77, state=80 'P', bufs=bufs@entry=0xabef2d94, count=count@entry=1, flags=flags@entry=0,
4 0x08372794 in receiveboost::asio::mutable_buffers_1 (flags=0, this=, impl=..., impl=..., ec=..., buffers=...)
5 receiveboost::asio::mutable_buffers_1 (this=, ec=..., flags=0, buffers=..., impl=...)
6 read_someboost::asio::mutable_buffers_1 (buffers=..., this=) at /usr/include/boost/asio/basic_stream_socket.hpp:768
7 read (n=4096,
8 read<SSLIOStreamDevice > (n=4096,
---Type to continue, or q to quit---
9 read<SSLIOStreamDevice > (n=4096,
10 read<SSLIOStreamDevice, boost::iostreams::detail::linked_streambuf<char, std::char_traits > > (n=4096,
11 read<boost::iostreams::detail::linked_streambuf<char, std::char_traits > > (src=, n=4096,
12 boost::iostreams::detail::indirect_streambuf<SSLIOStreamDevice, std::char_traits, std::allocator, boost::iostreams::bidirectional>::underflow (this=0xb4304bbc) at /usr/include/boost/iostreams/detail/streambuf/indirect_streambuf.hpp:258
13 0xb78b863b in ?? () from /usr/lib/i386-linux-gnu/libstdc++.so.6
14 0xb78d4cd5 in std::basic_istream<char, std::char_traits >& std::getline<char, std::char_traits, std::allocator >(std::basic_istream<char, std::char_traits >&, std::basic_string<char, std::char_traits, std::allocator >&, char) () from /usr/lib/i386-linux-gnu/libstdc++.so.6
15 0x08359155 in getline<char, std::char_traits, std::allocator > (str=..., is=...) at /usr/include/c++/4.8/bits/basic_string.h:2795
16 ReadHTTPRequestLine (stream=..., proto=@0xabef2f1c: 0, http_method=..., http_uri=...) at src/bitcoinrpc.cpp:379
17 0x0835bb8c in ServiceConnection (conn=conn@entry=0xb4304af0) at src/bitcoinrpc.cpp:974
18 0x0835dee8 in RPCAcceptHandler<boost::asio::ip::tcp, boost::asio::socket_acceptor_service > (acceptor=..., context=...,
19 0x08366e5d in operator()<void ()(boost::shared_ptr<boost::asio::basic_socket_acceptor >, boost::asio::ssl::context&, bool, AcceptedConnection , const boost::system::error_code&), boost::_bi::list1<const boost::system::error_code&> > (
20 operator()boost::system::error_code (a1=..., this=0xabef31d0) at /usr/include/boost/bind/bind_template.hpp:47
21 operator() (this=0xabef31d0) at /usr/include/boost/asio/detail/bind_handler.hpp:47
22 asio_handler_invoke<boost::asio::detail::binder1<boost::_bi::bind_t<void, void ()(boost::shared_ptr<boost::asio::basic_socketacceptor >, boost::asio::ssl::context&, bool, AcceptedConnection , boost::system::error_code const&), boost::_bi::list5boost::_bi::value<boost::shared_ptr<boost::asio::basic_socket_acceptor >, boost::reference_wrapperboost::asio::ssl::context, boost::_bi::value, boost::bi::value<AcceptedConnectionImpl >, boost::arg<1> ( )()> >, boost::system::error_code> > (
23 invoke<boost::asio::detail::binder1<boost::_bi::bind_t<void, void ()(boost::shared_ptr<boost::asio::basic_socketacceptor >, boost::asio::ssl::context&, bool, AcceptedConnection , boost::system::error_code const&), boost::_bi::list5boost::_bi::value<boost::shared_ptr<boost::asio::basic_socket_acceptor >, boost::reference_wrapperboost::asio::ssl::context, boost::_bi::value, boost::bi::value<AcceptedConnectionImpl >, boost::arg<1> (_)()> >, boost::system::error_code>, boost::_bi::bindt<void, void ()(boost::shared_ptrboost::asio::basic_socket_acceptor, boost::asio::ssl::context&, bool, AcceptedConnection , boost::system::error_code const&), boost::_bi::list5boost::_bi::value<boost::shared_ptr<boost::asio::basic_socket_acceptor >, boost::reference_wrapperboost::asio::ssl::context, boost::_bi::value---Type to continue, or q to quit---