arvidn / libtorrent

an efficient feature complete C++ bittorrent implementation
http://libtorrent.org
Other
5.23k stars 992 forks source link

libtorrent 1.2.1-11 DHT seg-fault on debian9 amd64 host os. #5324

Closed userdocs closed 3 years ago

userdocs commented 3 years ago

Please provide the following information

https://gist.githubusercontent.com/userdocs/88e99752d39defad236caffae870f575/raw/9db7281e484a905d4bc416c91dd737a5f4c19420/stretch.nox.sh

bash <(curl -sL git.io/JII1Q) all

I can build qbittorrent 4.3.1 against libtorrent (qt and libtorrent statically linked into qbit) with this outcome when the host os is Debian 9 amd64

root@localhost:~# ldd qbittorrent-build/completed/qbittorrent-nox
        linux-vdso.so.1 (0x00007ffe6dd94000)
        libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007fce63b15000)
        libssl.so.1.1 => /usr/lib/x86_64-linux-gnu/libssl.so.1.1 (0x00007fce638a9000)
        libcrypto.so.1.1 => /usr/lib/x86_64-linux-gnu/libcrypto.so.1.1 (0x00007fce6340f000)
        libboost_system.so.1.62.0 => /usr/lib/x86_64-linux-gnu/libboost_system.so.1.62.0 (0x00007fce6320b000)
        libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fce62fee000)
        libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fce62dea000)
        libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007fce62a68000)
        libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fce62764000)
        libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007fce6254d000)
        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fce621ae000)
        /lib64/ld-linux-x86-64.so.2 (0x00007fce64efa000)
        librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007fce61fa6000)

The problem?

qBittorrent version: v4.3.1

Caught signal: SIGSEGV
Stack trace:
  qbittorrent-build/completed/qbittorrent-nox-plusdht : libtorrent::dht::traversal_algorithm::add_entry(libtorrent::digest32<160l> const&, boost::asio::ip::basic_endpoint<boost::asio::ip::udp> const&, libtorrent::flags::bitfield_flag<unsigned char, libtorrent::dht::observer_flags_tag, void>)+0x8d2  [0x56483bd5d212]
  qbittorrent-build/completed/qbittorrent-nox-plusdht : ()+0x4f2538  [0x56483bd5d538]
  qbittorrent-build/completed/qbittorrent-nox-plusdht : libtorrent::dht::look_for_nodes(char const*, boost::asio::ip::udp const&, libtorrent::bdecode_node const&, std::function<void (libtorrent::dht::node_endpoint const&)>)+0x190  [0x56483bd5b5f0]
  qbittorrent-build/completed/qbittorrent-nox-plusdht : libtorrent::dht::traversal_observer::reply(libtorrent::dht::msg const&)+0x142  [0x56483bd5b862]
  qbittorrent-build/completed/qbittorrent-nox-plusdht : libtorrent::dht::find_data_observer::reply(libtorrent::dht::msg const&)+0x20b  [0x56483be0ae7b]
  qbittorrent-build/completed/qbittorrent-nox-plusdht : libtorrent::dht::get_peers_observer::reply(libtorrent::dht::msg const&)+0x1aa  [0x56483be0ee6a]
  qbittorrent-build/completed/qbittorrent-nox-plusdht : libtorrent::dht::rpc_manager::incoming(libtorrent::dht::msg const&, libtorrent::digest32<160l>*)+0x760  [0x56483bd58170]
  qbittorrent-build/completed/qbittorrent-nox-plusdht : libtorrent::dht::node::incoming(libtorrent::aux::listen_socket_handle const&, libtorrent::dht::msg const&)+0x20f  [0x56483bd4548f]
  qbittorrent-build/completed/qbittorrent-nox-plusdht : libtorrent::dht::dht_tracker::incoming_packet(libtorrent::aux::listen_socket_handle const&, boost::asio::ip::basic_endpoint<boost::asio::ip::udp> const&, libtorrent::span<char const>)+0x319  [0x56483bd38859]
  qbittorrent-build/completed/qbittorrent-nox-plusdht : libtorrent::aux::session_impl::on_udp_packet(std::weak_ptr<libtorrent::aux::session_udp_socket>, std::weak_ptr<libtorrent::aux::listen_socket_t>, libtorrent::aux::transport, boost::system::error_code const&)+0xd9a  [0x56483bc0641a]
  qbittorrent-build/completed/qbittorrent-nox-plusdht : boost::asio::detail::reactive_null_buffers_op<libtorrent::aux::allocating_handler<std::_Bind<std::_Mem_fn<void (libtorrent::aux::session_impl::*)(std::weak_ptr<libtorrent::aux::session_udp_socket>, std::weak_ptr<libtorrent::aux::listen_socket_t>, libtorrent::aux::transport, boost::system::error_code const&)> (libtorrent::aux::session_impl*, std::weak_ptr<libtorrent::aux::session_udp_socket>, std::weak_ptr<libtorrent::aux::listen_socket_t>, libtorrent::aux::transport, std::_Placeholder<1>)>, 400ul> >::do_complete(boost::asio::detail::task_io_service*, boost::asio::detail::task_io_service_operation*, boost::system::error_code const&, unsigned long)+0x105  [0x56483bc31035]
  qbittorrent-build/completed/qbittorrent-nox-plusdht : boost::asio::detail::epoll_reactor::descriptor_state::do_complete(boost::asio::detail::task_io_service*, boost::asio::detail::task_io_service_operation*, boost::system::error_code const&, unsigned long)+0x1e6  [0x56483bc1ce36]
  qbittorrent-build/completed/qbittorrent-nox-plusdht : ()+0x3674d8  [0x56483bbd24d8]
  /usr/lib/x86_64-linux-gnu/libstdc++.so.6 : ()+0xb9e6f  [0x7fc0a0253e6f]
  /lib/x86_64-linux-gnu/libpthread.so.0 : ()+0x74a4  [0x7fc0a07274a4]
  /lib/x86_64-linux-gnu/libc.so.6 : clone()+0x3f  [0x7fc09f9c8d0f]
Segmentation fault

Examples:

Note, you need the libs installed which you can get with the script

bash <(curl -sL git.io/JII1Q)

WORKS: DHT is off using b2 flag dht=off

https://github.com/userdocs/filehosting/raw/master/qbittorrent-nox-nodht

Note: Beware, this will work in a debian 9 docker where the host os is NOT Debian 9.

FAIL (host os / non docker): DHT is on using b2 flag dht=on or defaults to on if absent.

https://github.com/userdocs/filehosting/raw/master/qbittorrent-nox-plusdht

conclusion

There is a specific probelm with the dht module and the host os being debian 9.

Can you help identify the cause?

userdocs commented 3 years ago

btw this has been discussed before:

https://github.com/arvidn/libtorrent/issues/4625

https://github.com/qbittorrent/qBittorrent/issues/11882

it happens with current dependencies (boost 1.62 > 1.74 openssl 1.1.0 > 1.1.1 and so on) or system libs so think we should not focus on that part.

All i can say for certain is dht + debian9 breaks something.

userdocs commented 3 years ago

gdb

(gdb) run
Starting program: /root/qbittorrent-build/completed/qbittorrent-nox
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
[New Thread 0x7ffff604f700 (LWP 6397)]
[New Thread 0x7ffff584e700 (LWP 6398)]
[New Thread 0x7ffff504d700 (LWP 6399)]
[New Thread 0x7ffff484c700 (LWP 6400)]
[New Thread 0x7fffe7909700 (LWP 6401)]
[New Thread 0x7fffe7108700 (LWP 6402)]
[New Thread 0x7fffe6907700 (LWP 6403)]

******** Information ********
To control qBittorrent, access the Web UI at http://localhost:8080
The Web UI administrator username is: admin
The Web UI administrator password is still the default one: adminadmin
This is a security risk, please consider changing your password from program preferences.

Thread 3 "qbittorrent-nox" received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7ffff584e700 (LWP 6398)]
0x0000555555a46212 in libtorrent::dht::traversal_algorithm::add_entry(libtorrent::digest32<160l> const&, boost::asio::ip::basic_endpoint<boost::asio::ip::udp> const&, libtorrent::flags::bitfield_flag<unsigned char, libtorrent::dht::observer_flags_tag, void>) ()

Is this where it all starts?

https://github.com/arvidn/libtorrent/blob/0f0afec8c8025cb55dfd2f36612d4bf61a29ff8a/include/libtorrent/kademlia/traversal_algorithm.hpp#L81

userdocs commented 3 years ago

@arvidn it turns out, after much testing and confusing, this is specific to the vps provider i used to build it and maybe other very particular circumstances - https://github.com/arvidn/libtorrent/issues/4625

So this is a real issue with some hardware relationship that is not currently understood but it is not an issue in the sense this problem occurs at all times.

We can close this issue if you feel it's not your problem, but if you have any insight or questions as to why this would only happen with debian 9 and certain conditions (linode vps all types or armv7) i will be happy to provide any info you need.