asio
asio copied to clipboard
deadlock when canceling deadline_timer from another thread (boost::ip::udp::resolver->async_resolve)
I got a deadlock when canceling a deadline timer from boost::ip::udp::resolver->async_resolve
Or maybe it happened because the deadline_timer tried to cancel the ip::udp::resolver?
Either way, there is some thread safety issue going on for a really basic and important functionality needed.
My guess is that async_resolve tried to cancel from another thread while the deadline_timer was running at the same time.
The purpose of this was to just put a timeout on async_resolve.
versions: ubuntu 22.04 x64 boost 1.85.0 g++ (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
source code:
https://github.com/bottiger1/sm-ext-socket/blob/9effb1b4a06f9c8a8003fcc253f35a2a63ce8664/Socket.cpp#L526
stack trace:
futex_wait (private=0, expected=2, futex_word=0x7f4f2ea7bc20) at ../sysdeps/nptl/futex-internal.h:146
#0 futex_wait (private=0, expected=2, futex_word=0x7f4f2ea7bc20) at ../sysdeps/nptl/futex-internal.h:146
#1 __GI___lll_lock_wait (futex=futex@entry=0x7f4f2ea7bc20, private=0) at ./nptl/lowlevellock.c:49
#2 0x00007f4f438c8002 in lll_mutex_lock_optimized (mutex=0x7f4f2ea7bc20) at ./nptl/pthread_mutex_lock.c:48
#3 ___pthread_mutex_lock (mutex=0x7f4f2ea7bc20) at ./nptl/pthread_mutex_lock.c:93
#4 0x00007f4f0b831760 in boost::asio::detail::posix_mutex::lock (this=0x7f4f2ea7bc20) at /home/tf2/boost_1_85_0/boost/asio/detail/posix_mutex.hpp:52
#5 0x00007f4f0b83223a in boost::asio::detail::conditionally_enabled_mutex::scoped_lock::scoped_lock (this=0x7ffce09ac460, m=...) at /home/tf2/boost_1_85_0/boost/asio/detail/conditionally_enabled_mutex.hpp:55
#6 0x00007f4f0b85a201 in boost::asio::detail::epoll_reactor::schedule_timer<boost::asio::time_traits<boost::posix_time::ptime> > (this=0x7f4f2ea7bbe0, queue=..., time=..., timer=..., op=0x7f4ed10e9300) at /home/tf2/boost_1_85_0/boost/asio/detail/impl/epoll_reactor.hpp:51
#7 0x00007f4f0b82e57f in boost::asio::detail::deadline_timer_service<boost::asio::time_traits<boost::posix_time::ptime> >::async_wait<Socket<boost::asio::ip::udp>::SendTo(const string&, char const*, uint16_t)::<lambda(const boost::system::error_code&)>, boost::asio::any_io_executor>(boost::asio::detail::deadline_timer_service<boost::asio::time_traits<boost::posix_time::ptime> >::implementation_type &, struct {...} &, const boost::asio::any_io_executor &) (this=0x7f4f12eb80d0, impl=..., handler=..., io_ex=...) at /home/tf2/boost_1_85_0/boost/asio/detail/deadline_timer_service.hpp:272
#8 0x00007f4f0b82e281 in boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::any_io_executor>::initiate_async_wait::operator()<Socket<boost::asio::ip::udp>::SendTo(const string&, char const*, uint16_t)::<lambda(const boost::system::error_code&)> >(struct {...} &&) const (this=0x7ffce09ac5c0, handler=...) at /home/tf2/boost_1_85_0/boost/asio/basic_deadline_timer.hpp:691
#9 0x00007f4f0b82e155 in boost::asio::detail::completion_handler_async_result<Socket<boost::asio::ip::udp>::SendTo(const string&, char const*, uint16_t)::<lambda(const boost::system::error_code&)>, void(boost::system::error_code)>::initiate<boost::asio::basic_deadline_timer<boost::posix_time::ptime>::initiate_async_wait, Socket<boost::asio::ip::udp>::SendTo(const string&, char const*, uint16_t)::<lambda(const boost::system::error_code&)> >(boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::any_io_executor>::initiate_async_wait &&, struct {...} &&) (initiation=..., token=...) at /home/tf2/boost_1_85_0/boost/asio/async_result.hpp:320
#10 0x00007f4f0b82e101 in boost::asio::async_initiate<Socket<boost::asio::ip::udp>::SendTo(const string&, char const*, uint16_t)::<lambda(const boost::system::error_code&)>, void(boost::system::error_code), boost::asio::basic_deadline_timer<boost::posix_time::ptime>::initiate_async_wait>(boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::any_io_executor>::initiate_async_wait &&, boost::asio::type_identity_t &) (initiation=..., token=...) at /home/tf2/boost_1_85_0/boost/asio/async_result.hpp:619
#11 0x00007f4f0b82e099 in boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::any_io_executor>::async_wait<Socket<boost::asio::ip::udp>::SendTo(const string&, char const*, uint16_t)::<lambda(const boost::system::error_code&)> >(struct {...} &&) (this=0x7f4ed33a6a70, token=...) at /home/tf2/boost_1_85_0/boost/asio/basic_deadline_timer.hpp:658
#12 0x00007f4f0b82de19 in Socket<boost::asio::ip::udp>::SendTo at /home/tf2/extensions/sm-ext-socket/Socket.cpp:543