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

Do not wait for cancellation signal #4664

Merged

Conversation

pwojcikdev
Copy link
Contributor

@pwojcikdev pwojcikdev commented Jul 1, 2024

Waiting for cancellation signal is unnecessary and was causing a deadlock in tcp_listener class.

Thread 37 (LWP 25214):
#0  0x00007fa2b77c388d in syscall () from target:/lib/x86_64-linux-gnu/libc.so.6
#1  0x000055dc7f386491 in std::__atomic_futex_unsigned_base::_M_futex_wait_until(unsigned int*, unsigned int, bool, std::chrono::duration<long, std::ratio<1l, 1l> >, std::chrono::duration<long, std::ratio<1l, 1000000000l> >) ()
#2  0x000055dc7e9d1175 in std::__atomic_futex_unsigned<2147483648u>::_M_load_and_test_until (__ns=..., __s=..., __has_timeout=<optimized out>, __mo=<optimized out>, __equal=<optimized out>, __operand=<optimized out>, __assumed=<optimized out>, this=<optimized out>) at /tmp/src/submodules/boost/libs/asio/include/boost/asio/scheduler.hpp:646
#3  std::__atomic_futex_unsigned<2147483648u>::_M_load_and_test (__mo=<optimized out>, __equal=<optimized out>, __operand=<optimized out>, __assumed=<optimized out>, this=<optimized out>) at /usr/include/x86_64-linux-gnu/bits/gthr-default.h:159
#4  std::__atomic_futex_unsigned<2147483648u>::_M_load_when_equal (__mo=<error reading variable: dwarf2_find_location_expression: Corrupted DWARF expression.>, __val=<error reading variable: dwarf2_find_location_expression: Corrupted DWARF expression.>, this=<error reading variable: dwarf2_find_location_expression: Corrupted DWARF expression.>) at /usr/include/x86_64-linux-gnu/bits/gthr-default.h:213
#5  std::__future_base::_State_baseV2::wait (this=<error reading variable: dwarf2_find_location_expression: Corrupted DWARF expression.>) at /tmp/src/submodules/boost/libs/asio/include/boost/asio/execution/impl/bad_address_cast.hpp:336
#6  std::__basic_future<void>::wait (this=0x7fa23cff73b0, this@entry=<error reading variable: dwarf2_find_location_expression: Corrupted DWARF expression.>) at /tmp/src/submodules/boost/libs/asio/include/boost/asio/execution/impl/bad_address_cast.hpp:694
#7  nano::async::cancellation::emit (type=boost::asio::cancellation_type::all, type@entry=<error reading variable: dwarf2_find_location_expression: Corrupted DWARF expression.>, this=0x7fa1e0074838, this@entry=<error reading variable: dwarf2_find_location_expression: Corrupted DWARF expression.>) at /tmp/src/submodules/boost/libs/asio/include/boost/asio/detail/atomic_futex.h:57
#8  nano::async::task::cancel (this=0x7fa1e0074820, this@entry=<error reading variable: dwarf2_find_location_expression: Corrupted DWARF expression.>) at /tmp/src/submodules/boost/libs/asio/include/boost/asio/detail/atomic_futex.h:143
#9  nano::transport::tcp_listener::timeout() () at /tmp/src/submodules/boost/libs/asio/include/boost/asio/ip/string_view:212
#10 0x000055dc7e9d1369 in nano::transport::tcp_listener::run_cleanup() () at /tmp/src/submodules/boost/libs/asio/include/boost/asio/ip/string_view:171
#11 0x000055dc7f3b89f4 in execute_native_thread_routine ()
#12 0x00007fa2b7739ac3 in ?? () from target:/lib/x86_64-linux-gnu/libc.so.6
#13 0x00007fa2b77caa04 in clone () from target:/lib/x86_64-linux-gnu/libc.so.6

Thread 35 (LWP 25212):
#0  0x00007fa2b77362c0 in ?? () from target:/lib/x86_64-linux-gnu/libc.so.6
#1  0x00007fa2b773d002 in pthread_mutex_lock () from target:/lib/x86_64-linux-gnu/libc.so.6
#2  0x000055dc7e9d00d0 in __gthread_mutex_lock (__mutex=0x55dc847a67e8) at /tmp/src/submodules/boost/libs/asio/include/boost/asio/socket_holder.hpp:749
#3  std::mutex::lock (this=0x55dc847a67e8) at /tmp/src/build/nano/node/tcp_listener.cpp:100
#4  nano::mutex::lock (this=0x55dc847a67e8) at /tmp/src/submodules/boost/libs/asio/include/boost/asio/detail/std_mutex.h:77
#5  std::unique_lock<nano::mutex>::lock (this=0x7fa23dff8be0) at /tmp/src/submodules/boost/libs/system/include/boost/system/detail/use_awaitable.hpp:139
#6  std::unique_lock<nano::mutex>::unique_lock (__m=..., this=0x7fa23dff8be0) at /tmp/src/submodules/boost/libs/system/include/boost/system/detail/use_awaitable.hpp:69
#7  nano::transport::tcp_listener::connect(boost::asio::ip::address, unsigned short) () at /tmp/src/submodules/boost/libs/asio/include/boost/asio/ip/string_view:223
#8  0x000055dc7e9badc2 in nano::transport::tcp_channels::start_tcp (this=<optimized out>, endpoint=...) at /usr/include/x86_64-linux-gnu/bits/socket_ops.ipp:60
#9  0x000055dc7e919cda in nano::network::merge_peer (peer_a=..., this=<optimized out>) at /tmp/src/submodules/boost/libs/asio/include/boost/asio/detail/unordered_map.h:334
#10 nano::network::merge_peer (this=<optimized out>, peer_a=...) at /tmp/src/submodules/boost/libs/asio/include/boost/asio/detail/unordered_map.h:328
#11 0x000055dc7eaf6d65 in (anonymous namespace)::process_visitor::keepalive (this=0x7fa23dff8e20, message=...) at /tmp/src/build/nano/node/messages.hpp:177
#12 0x000055dc7eaf72c5 in nano::message_processor::process(nano::message const&, std::shared_ptr<nano::transport::channel> const&) () at /tmp/src/build/nano/node/messages.hpp:287
#13 0x000055dc7eaf8d45 in nano::message_processor::run_batch(std::unique_lock<nano::mutex>&) () at /tmp/src/build/nano/node/messages.hpp:146
#14 0x000055dc7eaf91c2 in nano::message_processor::run() () at /tmp/src/build/nano/node/messages.hpp:115
#15 0x000055dc7eaf92bd in operator() (__closure=0x55dc8036a388) at /tmp/src/build/nano/node/messages.hpp:35
#16 std::__invoke_impl<void, nano::message_processor::start()::<lambda()> > (__f=...) at /tmp/src/nano/lib/std_function.h:61
#17 std::__invoke<nano::message_processor::start()::<lambda()> > (__fn=...) at /tmp/src/nano/lib/std_function.h:96
#18 std::thread::_Invoker<std::tuple<nano::message_processor::start()::<lambda()> > >::_M_invoke<0> (this=0x55dc8036a388) at /usr/include/c++/11/exception_implementation.hpp:259
#19 std::thread::_Invoker<std::tuple<nano::message_processor::start()::<lambda()> > >::operator() (this=0x55dc8036a388) at /usr/include/c++/11/exception_implementation.hpp:266
#20 std::thread::_State_impl<std::thread::_Invoker<std::tuple<nano::message_processor::start()::{lambda()#1}> > >::_M_run() () at /usr/include/c++/11/exception_implementation.hpp:211
#21 0x000055dc7f3b89f4 in execute_native_thread_routine ()
#22 0x00007fa2b7739ac3 in ?? () from target:/lib/x86_64-linux-gnu/libc.so.6
#23 0x00007fa2b77caa04 in clone () from target:/lib/x86_64-linux-gnu/libc.so.6

// More IO threads with the same stacktrace
// ....

@pwojcikdev pwojcikdev changed the title Do not wait for cancelation signal Do not wait for cancellation signal Jul 1, 2024
@pwojcikdev pwojcikdev force-pushed the aysnc-cancelation-do-not-wait branch from 6ef44cd to e73f914 Compare July 1, 2024 12:36
@@ -49,12 +49,11 @@ class cancellation
};

public:
void emit (asio::cancellation_type type = asio::cancellation_type::all)
auto emit (asio::cancellation_type type = asio::cancellation_type::all)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the returned value need to be used anywhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's nice to have and I just added a test that uses this functionality

gr0vity-dev pushed a commit to gr0vity-dev/nano-node that referenced this pull request Jul 1, 2024
@qwahzi qwahzi added this to the V27 milestone Jul 1, 2024
@pwojcikdev pwojcikdev force-pushed the aysnc-cancelation-do-not-wait branch from 78578b5 to ac4c773 Compare July 1, 2024 17:16
gr0vity-dev pushed a commit to gr0vity-dev/nano-node that referenced this pull request Jul 2, 2024
gr0vity-dev pushed a commit to gr0vity-dev/nano-node that referenced this pull request Jul 2, 2024
@pwojcikdev pwojcikdev merged commit 6a802b2 into nanocurrency:develop Jul 2, 2024
25 of 28 checks passed
@pwojcikdev pwojcikdev deleted the aysnc-cancelation-do-not-wait branch July 2, 2024 07:48
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

Successfully merging this pull request may close these issues.

3 participants