Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assertion failure in peer_connection.cpp::on_receive_data #7752

Open
Him188 opened this issue Oct 15, 2024 · 2 comments
Open

Assertion failure in peer_connection.cpp::on_receive_data #7752

Him188 opened this issue Oct 15, 2024 · 2 comments

Comments

@Him188
Copy link

Him188 commented Oct 15, 2024

Please provide the following information

libtorrent version (or branch): 2.0.10

platform/architecture: macOS AArch64

compiler and compiler version:
Apple clang version 16.0.0 (clang-1600.0.26.3)
Target: arm64-apple-darwin24.0.0
Thread model: posix

please describe what symptom you see, what you would expect to see instead and
how to reproduce it.


I'm seeing this error when downloading a torrent. I can't tell how to reproduce it, because it seems that this happens randomly.

Luckly I was using a debug build so I can provide stack trace:

assertion failed. Please file a bugreport at https://github.com/arvidn/libtorrent/issues
Please include the following information:

version: 2.0.10.0-dacf64c50

file: '/Users/him188/Projects/ani/torrent/anitorrent/anitorrent-native/build-ci/_deps/libtorrent-src/src/peer_connection.cpp'
line: 6099
function: on_receive_data
expression: bytes_transferred > 0 || error

stack:
1: libtorrent::assert_fail(char const*, int, char const*, char const*, char const*, int)
2: libtorrent::peer_connection::on_receive_data(boost::system::error_code const&, unsigned long)
3: void libtorrent::aux::handler<libtorrent::peer_connection, void (libtorrent::peer_connection::*)(boost::system::error_code const&, unsigned long), &libtorrent::peer_connection::on_receive_data(boost::system::error_code const&, unsigned long), &libtorrent::peer_connection::on_error(boost::system::error_code const&), &libtorrent::peer_connection::on_exception(std::exception const&), libtorrent::aux::handler_storage<440ul, (libtorrent::aux::HandlerName)1>, &libtorrent::peer_connection::m_read_handler_storage>::operator()<boost::system::error_code const&, unsigned long const&>(boost::system::error_code const&, unsigned long const&)
4: void boost::asio::ssl::detail::read_op<boost::asio::mutable_buffer>::call_handler<libtorrent::aux::handler<libtorrent::peer_connection, void (libtorrent::peer_connection::*)(boost::system::error_code const&, unsigned long), &libtorrent::peer_connection::on_receive_data(boost::system::error_code const&, unsigned long), &libtorrent::peer_connection::on_error(boost::system::error_code const&), &libtorrent::peer_connection::on_exception(std::exception const&), libtorrent::aux::handler_storage<440ul, (libtorrent::aux::HandlerName)1>, &libtorrent::peer_connection::m_read_handler_storage>>(libtorrent::aux::handler<libtorrent::peer_connection, void (libtorrent::peer_connection::*)(boost::system::error_code const&, unsigned long), &libtorrent::peer_connection::on_receive_data(boost::system::error_code const&, unsigned long), &libtorrent::peer_connection::on_error(boost::system::error_code const&), &libtorrent::peer_connection::on_exception(std::exception const&), libtorrent::aux::handler_storage<440ul, (libtorrent::aux::HandlerName)1>, &libtorrent::peer_connection::m_read_handler_storage>&, boost::system::error_code const&, unsigned long const&) const
5: boost::asio::ssl::detail::io_op<libtorrent::aux::noexcept_move_only<boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::any_io_executor>>, boost::asio::ssl::detail::read_op<boost::asio::mutable_buffer>, libtorrent::aux::handler<libtorrent::peer_connection, void (libtorrent::peer_connection::*)(boost::system::error_code const&, unsigned long), &libtorrent::peer_connection::on_receive_data(boost::system::error_code const&, unsigned long), &libtorrent::peer_connection::on_error(boost::system::error_code const&), &libtorrent::peer_connection::on_exception(std::exception const&), libtorrent::aux::handler_storage<440ul, (libtorrent::aux::HandlerName)1>, &libtorrent::peer_connection::m_read_handler_storage>>::operator()(boost::system::error_code, unsigned long, int)
6: boost::asio::detail::binder2<boost::asio::ssl::detail::io_op<libtorrent::aux::noexcept_move_only<boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::any_io_executor>>, boost::asio::ssl::detail::read_op<boost::asio::mutable_buffer>, libtorrent::aux::handler<libtorrent::peer_connection, void (libtorrent::peer_connection::*)(boost::system::error_code const&, unsigned long), &libtorrent::peer_connection::on_receive_data(boost::system::error_code const&, unsigned long), &libtorrent::peer_connection::on_error(boost::system::error_code const&), &libtorrent::peer_connection::on_exception(std::exception const&), libtorrent::aux::handler_storage<440ul, (libtorrent::aux::HandlerName)1>, &libtorrent::peer_connection::m_read_handler_storage>>, boost::system::error_code, unsigned long>::operator()()
7: void boost::asio::detail::handler_work<boost::asio::ssl::detail::io_op<libtorrent::aux::noexcept_move_only<boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::any_io_executor>>, boost::asio::ssl::detail::read_op<boost::asio::mutable_buffer>, libtorrent::aux::handler<libtorrent::peer_connection, void (libtorrent::peer_connection::*)(boost::system::error_code const&, unsigned long), &libtorrent::peer_connection::on_receive_data(boost::system::error_code const&, unsigned long), &libtorrent::peer_connection::on_error(boost::system::error_code const&), &libtorrent::peer_connection::on_exception(std::exception const&), libtorrent::aux::handler_storage<440ul, (libtorrent::aux::HandlerName)1>, &libtorrent::peer_connection::m_read_handler_storage>>, boost::asio::any_io_executor, void>::complete<boost::asio::detail::binder2<boost::asio::ssl::detail::io_op<libtorrent::aux::noexcept_move_only<boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::any_io_executor>>, boost::asio::ssl::detail::read_op<boost::asio::mutable_buffer>, libtorrent::aux::handler<libtorrent::peer_connection, void (libtorrent::peer_connection::*)(boost::system::error_code const&, unsigned long), &libtorrent::peer_connection::on_receive_data(boost::system::error_code const&, unsigned long), &libtorrent::peer_connection::on_error(boost::system::error_code const&), &libtorrent::peer_connection::on_exception(std::exception const&), libtorrent::aux::handler_storage<440ul, (libtorrent::aux::HandlerName)1>, &libtorrent::peer_connection::m_read_handler_storage>>, boost::system::error_code, unsigned long>>(boost::asio::detail::binder2<boost::asio::ssl::detail::io_op<libtorrent::aux::noexcept_move_only<boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::any_io_executor>>, boost::asio::ssl::detail::read_op<boost::asio::mutable_buffer>, libtorrent::aux::handler<libtorrent::peer_connection, void (libtorrent::peer_connection::*)(boost::system::error_code const&, unsigned long), &libtorrent::peer_connection::on_receive_data(boost::system::error_code const&, unsigned long), &libtorrent::peer_connection::on_error(boost::system::error_code const&), &libtorrent::peer_connection::on_exception(std::exception const&), libtorrent::aux::handler_storage<440ul, (libtorrent::aux::HandlerName)1>, &libtorrent::peer_connection::m_read_handler_storage>>, boost::system::error_code, unsigned long>&, boost::asio::ssl::detail::io_op<libtorrent::aux::noexcept_move_only<boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::any_io_executor>>, boost::asio::ssl::detail::read_op<boost::asio::mutable_buffer>, libtorrent::aux::handler<libtorrent::peer_connection, void (libtorrent::peer_connection::*)(boost::system::error_code const&, unsigned long), &libtorrent::peer_connection::on_receive_data(boost::system::error_code const&, unsigned long), &libtorrent::peer_connection::on_error(boost::system::error_code const&), &libtorrent::peer_connection::on_exception(std::exception const&), libtorrent::aux::handler_storage<440ul, (libtorrent::aux::HandlerName)1>, &libtorrent::peer_connection::m_read_handler_storage>>&)
8: boost::asio::detail::reactive_socket_recv_op<boost::asio::mutable_buffer, boost::asio::ssl::detail::io_op<libtorrent::aux::noexcept_move_only<boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::any_io_executor>>, boost::asio::ssl::detail::read_op<boost::asio::mutable_buffer>, libtorrent::aux::handler<libtorrent::peer_connection, void (libtorrent::peer_connection::*)(boost::system::error_code const&, unsigned long), &libtorrent::peer_connection::on_receive_data(boost::system::error_code const&, unsigned long), &libtorrent::peer_connection::on_error(boost::system::error_code const&), &libtorrent::peer_connection::on_exception(std::exception const&), libtorrent::aux::handler_storage<440ul, (libtorrent::aux::HandlerName)1>, &libtorrent::peer_connection::m_read_handler_storage>>, boost::asio::any_io_executor>::do_complete(void*, boost::asio::detail::scheduler_operation*, boost::system::error_code const&, unsigned long)
9: boost::asio::detail::scheduler_operation::complete(void*, boost::system::error_code const&, unsigned long)
10: boost::asio::detail::scheduler::do_run_one(boost::asio::detail::conditionally_enabled_mutex::scoped_lock&, boost::asio::detail::scheduler_thread_info&, boost::system::error_code const&)
11: boost::asio::detail::scheduler::run(boost::system::error_code&)
12: boost::asio::io_context::run()
13: libtorrent::session::start(libtorrent::flags::bitfield_flag<unsigned char, libtorrent::session_fl

The project was built using CMake with the following configuration:

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_C_STANDARD 17)

add_compile_definitions(TORRENT_HAVE_MMAP=0)
add_compile_definitions(TORRENT_ABI_VERSION=3) # Hide all deprecated APIs

FetchContent_Declare(
        libtorrent
        GIT_REPOSITORY https://github.com/arvidn/libtorrent.git
        GIT_TAG v2.0.10
)
...

Boost version is 1.85.0.

@arvidn
Copy link
Owner

arvidn commented Oct 20, 2024

This assertion makes sure that the boost.asio API is behaving as expected. async_read_some() should never call the handler if 0 bytes were read. If the connection closed (which under plain posix sockets would cause read() to return 0) boost asio is supposed to call the handler with an error indicating end-of-file. Hence the || error in there.

It appears that, in your case, the handler is called with 0 bytes without indicating an error. I suspect this is some unexpected interaction with your SSL library. Are you using regular OpenSSL or some other library implementing its API?

@Him188
Copy link
Author

Him188 commented Oct 20, 2024

Thanks for the reply. I'm using the regular Homebrew OpenSSL:

OpenSSL 3.3.2 3 Sep 2024 (Library: OpenSSL 3.3.2 3 Sep 2024)
$ which openssl
/opt/homebrew/bin/openssl

From CMakeCache.txt:

//Enables encryption in libtorrent
encryption:BOOL=ON

//build using GnuTLS instead of OpenSSL
gnutls:BOOL=OFF

//Path to a library.
OPENSSL_CRYPTO_LIBRARY:FILEPATH=/opt/homebrew/Cellar/openssl@3/3.3.2/lib/libcrypto.dylib

//Path to a file.
OPENSSL_INCLUDE_DIR:PATH=/opt/homebrew/Cellar/openssl@3/3.3.2/include

//Path to a library.
OPENSSL_SSL_LIBRARY:FILEPATH=/opt/homebrew/Cellar/openssl@3/3.3.2/lib/libssl.dylib

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants