Skip to content

bitcoin-node segfaults when interrupted #123

Open
@ryanofsky

Description

@ryanofsky

Originally posted by @darosior in bitcoin/bitcoin#10102 (comment)

Not sure if it's worth sharing here but hey what's an 1300th comment.

Running bitcoin-node from bitcoin/bitcoin#29409 with commits 1045047a73a0b3ae15647ab5bf1829d27141b7cd..9ca113f326fc9ba2f661595283f4aef390df984d from this PR cherry-picked on top.

Simply compiled with cmake -B multiprocbuild/ -DWITH_MULTIPROCESS=ON && cmake --build multiprocbuild/ -j20. (Although i did have to apply the following diff to be able to compile on Debian stable.)

Expand diff to compile on Debian stable
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 6ae988ac90..ca0880b3cd 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -23,6 +23,7 @@ set(CLIENT_VERSION_BUILD 0)
 set(CLIENT_VERSION_RC 0)
 set(CLIENT_VERSION_IS_RELEASE "false")
 set(COPYRIGHT_YEAR "2024")
+set(FOUND_LIBATOMIC TRUE)
 
 # During the enabling of the CXX and CXXOBJ languages, we modify
 # CMake's compiler/linker invocation strings by appending the content
diff --git a/src/test/ipc_test.cpp b/src/test/ipc_test.cpp
index 91eba9214f..af37434980 100644
--- a/src/test/ipc_test.cpp
+++ b/src/test/ipc_test.cpp
@@ -62,7 +62,7 @@ void IpcPipeTest()
 
         auto connection_client = std::make_unique<mp::Connection>(loop, kj::mv(pipe.ends[0]));
         auto foo_client = std::make_unique<mp::ProxyClient<gen::FooInterface>>(
-            connection_client->m_rpc_system.bootstrap(mp::ServerVatId().vat_id).castAs<gen::FooInterface>(),
+            connection_client->m_rpc_system->bootstrap(mp::ServerVatId().vat_id).castAs<gen::FooInterface>(),
             connection_client.get(), /* destroy_connection= */ false);
         foo_promise.set_value(std::move(foo_client));
         disconnect_client = [&] { loop.sync([&] { connection_client.reset(); }); };

Just starting bitcoin-node and stopping it with a SIGKILL results in the following crash:

2024-12-03T20:49:29Z [ipc] {bitcoin-node-69380/bitcoin-node-69380} IPC client exception kj::Exception: kj/async-io-unix.c++:323: disconnected: ::read(fd, buffer, maxBytes): Connection reset by peer
stack: 7f53be1b41d4 7f53be1bf95b 7f53be15a911 7f53be1ab560 7f53be3147f0 7f53be30e0a0 7f53be3120f0 7f53be370bf0 7f53be36b6d0 7f53be361de0 7f53be35bea0 7f53be34e160 7f53be34ebc4 7f53be34b7a0 562975c42300 562975c4c8c0
2024-12-03T20:49:29Z [ipc] kj::Exception: kj/async-io-unix.c++:323: disconnected: ::read(fd, buffer, maxBytes): Connection reset by peer
stack: 7f53be1b41d4 7f53be1bf95b 7f53be15a911 7f53be1ab560 7f53be3147f0 7f53be30e0a0 7f53be3120f0 7f53be370bf0 7f53be36b6d0 7f53be361de0 7f53be35bea0 7f53be34e160 7f53be34ebc4 7f53be34b7a0 562975c42300 562975c4c8c0
2024-12-03T20:49:29Z [ipc] {bitcoin-node-69380/b-capnp-loop-69383} IPC client: unexpected network disconnect.
terminate called after throwing an instance of 'ipc::Exception'
  what():  kj::Exception: kj/async-io-unix.c++:323: disconnected: ::read(fd, buffer, maxBytes): Connection reset by peer
stack: 7f53be1b41d4 7f53be1bf95b 7f53be15a911 7f53be1ab560 7f53be3147f0 7f53be30e0a0 7f53be3120f0 7f53be370bf0 7f53be36b6d0 7f53be361de0 7f53be35bea0 7f53be34e160 7f53be34ebc4 7f53be34b7a0 562975c42300 562975c4c8c0
Aborted

The command i used to start it is ./multiprocbuild/src/bitcoin-node -regtest -ipcbind=unix -debug=ipc.

With a simple hacked up client which constructs an Init interface and stops, the crash becomes (still only when stopping bitcoin-node):

terminate called after throwing an instance of 'std::logic_error'
  what():  clientInvoke call made after disconnect
Aborted

Now if the client requested a thread before stopping, this becomes a segfault (still only when stopping bitcoin-node):

2024-12-03T21:02:50Z [ipc] {bitcoin-node-70275/bitcoin-node-70275} IPC client exception kj::Exception: kj/async-io-unix.c++:532: disconnected: ::writev(fd, iov.begin(), iov.size()): Broken pipe; iovTotal = 176; iov.size() = 2
stack: 7f70b535079f 7f70b5350cad 7f70b54a9544 7f70b54a9732 7f70b54a978a 7f70b550825d 7f70b5507180 7f70b55016d0 7f70b54f7de0 7f70b54f1ea0 7f70b54e4160 7f70b54e4bc4 7f70b54e17a0 56041e62f300 56041e6398c0
2024-12-03T21:02:50Z [ipc] {bitcoin-node-70275/b-capnp-loop-70278} IPC client: unexpected network disconnect.
Segmentation fault

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions