You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[v30.0rc3]bitcoin-node aborts with mining IPC interface usage #33554
one relevant detail here is that our rust code has evolved from what it looked like when I first reported #33463, and there I did not witness this behavior
now, every 10s, we receive a Sv2 CoinbaseOutputConstraints message, which is meant to set the coinbase parameters with regards to blockspace consumption (weight and sigops)
so everytime this message arrives, we create a fresh new BlockTemplate IPC client with those new parameters
we do not call destroy on the previous one, because we don't know if we could still receive a submitSolution associated with a template that was generated from it
so we keep clones of past BlockTemplate IPC client in memory (as many clones as templates generated from the same instance) and drop them all whenever there's a new chain tip (also without calling destroy)
(So far I'm not able to reproduce a crash with v30.0rc3, but that might just be because I was testing with regtest.)
The assert you see happening on line 289 just happens when the IPC client asks the server to execute multiple IPC calls simultaneously on the same thread. The IPC server does not expect this and currently aborts when it happens.
It is possible for the server to execute multiple IPC calls simultaneously, but the client needs to create more than one thread thread with ThreadMap.makeThread and assign different threads to the IPC calls that are supposed to execute simultaneously.
The server is pretty fragile and unhelpful for failing this way, but a recently merged PR bitcoin-core/libmultiprocess#214 should make the situation better by having the server return with a "thread busy" error instead of aborting when this happens.
Just to be clear about next steps, the node aborts should be prevented by bitcoin-core/libmultiprocess#214 which is set to be backported in #33519. (The aborts were originally intentional but are an unnecessarily harsh way to fail, so those PR's replace them with IPC "thread busy" errors.)
Regardless of this, the rust client code needs to be changed to either not make other IPC calls at the same time as there is an active waitNext() IPC call, or to just create more server threads and request the waitNext call to run on a different thread than the other IPC calls.
I updated the code with the advice above and bitcoin-node no longer crashes during normal operation... I can leave it running for hours without a crash.
But if I kill my rust code, it still causes a crash on bitcoin-node... I wonder if I'm still doing something wrong on shutdown?
But if I kill my rust code, it still causes a crash on bitcoin-node... I wonder if I'm still doing something wrong on shutdown?
This seems like a new crash I haven't seen before. Probably there is something the rust code could be doing differently to prevent the crash, but that wouldn't mean it is doing anything wrong, since the node should be able to avoid crashing on unclean shutdowns. Will look into this more and try to suggest changes and fix.
to be fair, the shutdown strategy on the rust code doesn't really do anything to try to be "clean"
when ctrl+c is hit, we simply break the loops of every spawned task and drop everything from memory (including records to whatever waitNext request that was still waiting for completion)
also worth mentioning that the steps listed above are not able to reproduce it deterministically
sometimes it happens, sometimes it doesn't happen
probably related to the order in which things are dropped from memory, which I assume capnp and capnp-rpc crates take as triggers for IPC signals for resource cleanup on the server side
It looks to me like there's not way great way for the rust client to avoid this problem, and this is something bitcoin-node should be changed to fix by (1) fixing the abort described in bitcoin-core/libmultiprocess#226 and (2) improving the mining interface so there is a way to interrupt waitNext calls.
I think currently the only reliable way to avoid triggering the abort is to avoid disconnecting until waitNext returns.
But this might be undesirable because there isn't currently a way to interrupt the waitNext call and have it return early. It would be good if bitcoin-node would address this by adding a new BlockTemplateinterruptWait method, or just have BlockTemplate destructor interrupt the wait. The client should have some clean way of interrupting the waitNext call if it no longer needs a new block so mining interface clients can shut down quickly and cleanly.
I have a question related to the approach I started taking with the insights coming from the crashes reported here.
following your advice, I'm no longer using one single server thread for everything... now there's one "static" server thread that's responsible for all non-blocking calls (e.g.: fetching some template data or submitting solution to some template)
and for waitNext, there's dedicated server thread(s)
the thing is, I still need to cater for incoming Sv2 CoinbaseOutputConstraints messages, and whenever that arrives, I need to make sure the BlockTemplate (or TemplateIpcClient as I'm aliasing on the rust code) that's used to kickstart the next waitNext loops has the correct block_reserved_weight and max_additional_sigops as defined on the Sv2 message.
and since I cannot interfere with server thread dedicated to the ongoing waitNext (because it would lead to crashes), I'm being forced to instantiate yet another server thread, just so I can instantiate the new BlockTemplate with the new coinbase constraints and kickstart the new waitNext loop
so my question is: by doing this, am I risking unbounded resource consumption on bitcoin-node? because basically I'm not taking any explicit steps to kill the server thread that was dedicated for waitNext loops under the previous coinbase constraints... the reference to ThreadIpcClient is simply dropped from memory, and that's it.
anyways, once the changes mentioned on the comment above take place, this should no longer be a relevant issue, because as soon as CoinbaseOutputConstraints arrived, I'd be able to kill the current waitNext call and simply use the same server thread for the new one, so the rust client would always be using only two server threads without any need for creating more server threads every time we had new coinbase constraints
but I felt I should ask anyways, because it seems like an important concept that's still foggy on my mental model for IPC
These are good questions. I opened #33575 to figure out how to cancel waitNext calls, and I think it should not be hard to provide that.
More broadly, I think I'd try just having a c++ "waiter" thread dedicated to running waitNext calls, and a c++ "worker" thread to run all other IPC operations besides waitNext. The "waiter" thread should be mostly blocked monitoring mempool and network, and the "worker" thread should be available to do anything else you might need like fetching and submitting block data.
With current v30 code, there is no mechanism to cancel waitNext calls, so I think simplest approach would be to create a new c++ thread for each waitNext call, effectively having multiple "waiter" threads and one "worker" thread. This will use more resources, but I would not expect it to take a lot more, because presumably block_reserved_weight and max_additional_sigops option values should not change very frequently, and new blocks being connected should provide an upper limit on how long waitNext calls stick around.
rephrasing my previous question in a more compact way:
is there a way to "kill" server threads?
because presumably block_reserved_weight and max_additional_sigops option values should not change very frequently
indeed, I think this will be relatively rare in practice... but it's still something that's not under our control, and on the current strategy it will lead to unbounded resource consumption on Bitcoin Core side (unless server threads could be killed)
Indirectly, yes. The server threads will destroy themselves as soon as they are no longer referenced, either by the client or an ongoing IPC call that is using them. So as long as the client is not holding references to threads it is not using, they will be cleaned up.
There is some cost to creating threads, so it's good to reuse them between calls, and why I recommended having dedicated "waiter" and "worker" threads. But if you wanted to create more threads than that for different calls it would probably work ok in practice.
and on the current strategy it will lead to unbounded resource consumption on Bitcoin Core side
As long as there is no way to cancel waitNext calls, it could lead to a lot of threads being created if you need to make many calls. I'd just expect the number to be pretty limited based on how many should be needed. After cancellation is implemented you should be able to get away with having just 2 threads total.
Indirectly, yes. The server threads will destroy themselves as soon as they are no longer referenced, either by the client or an ongoing IPC call that is using them. So as long as the client is not holding references to threads it is not using, they will be cleaned up.
ok I had AI tell me the same thing but didn't want to blindly trust it, so that's why I went out of my way to confirm that. Good to know.
then also what I said about unbounded resource consumption above is not true, since references to server threads for the old waitNext loops are dropped.
but still, ideally only 2 threads should be enough, and I guess we'll get there eventually.
Thanks will close. The original issue where then node crashes when a client requests to multiple IPC calls to execute simultaneously on the same worker thread should be fixed by bitcoin-core/libmultiprocess#214 and #33519 which replaces the crashes with "thread busy" errors.
The crash reported later where killing the rust code in the middle of a waitNext call causes the node to crash during shutdown (#33554 (comment)) isn't fixed yet but I created a separate issue to track it bitcoin-core/libmultiprocess#226. Also the new interruptWait method in #33676 should make the problem less likely to happen if the rust client uses it.
Activity
plebhash commentedon Oct 6, 2025
also reproducible on
v30-0rc1tagplebhash commentedon Oct 6, 2025
one relevant detail here is that our rust code has evolved from what it looked like when I first reported #33463, and there I did not witness this behavior
now, every 10s, we receive a Sv2
CoinbaseOutputConstraintsmessage, which is meant to set the coinbase parameters with regards to blockspace consumption (weight and sigops)so everytime this message arrives, we create a fresh new
BlockTemplateIPC client with those new parameterswe do not call
destroyon the previous one, because we don't know if we could still receive asubmitSolutionassociated with a template that was generated from itso we keep clones of past
BlockTemplateIPC client in memory (as many clones as templates generated from the same instance) and drop them all whenever there's a new chain tip (also without callingdestroy)ryanofsky commentedon Oct 7, 2025
(So far I'm not able to reproduce a crash with v30.0rc3, but that might just be because I was testing with regtest.)
The assert you see happening on line 289 just happens when the IPC client asks the server to execute multiple IPC calls simultaneously on the same thread. The IPC server does not expect this and currently aborts when it happens.
It is possible for the server to execute multiple IPC calls simultaneously, but the client needs to create more than one thread thread with ThreadMap.makeThread and assign different threads to the IPC calls that are supposed to execute simultaneously.
The server is pretty fragile and unhelpful for failing this way, but a recently merged PR bitcoin-core/libmultiprocess#214 should make the situation better by having the server return with a "thread busy" error instead of aborting when this happens.
ryanofsky commentedon Oct 7, 2025
Just to be clear about next steps, the node aborts should be prevented by bitcoin-core/libmultiprocess#214 which is set to be backported in #33519. (The aborts were originally intentional but are an unnecessarily harsh way to fail, so those PR's replace them with IPC "thread busy" errors.)
Regardless of this, the rust client code needs to be changed to either not make other IPC calls at the same time as there is an active
waitNext()IPC call, or to just create more server threads and request the waitNext call to run on a different thread than the other IPC calls.plebhash commentedon Oct 7, 2025
I updated the code with the advice above and
bitcoin-nodeno longer crashes during normal operation... I can leave it running for hours without a crash.But if I kill my rust code, it still causes a crash on
bitcoin-node... I wonder if I'm still doing something wrong on shutdown?steps to reproduce:
bitcoin-nodefrom Update libmultiprocess subtree in 30.x branch #335192025-10-06-abort-proxy-iobranchbitcoin-nodewith-ipc-bind=unix(connected totestnet4)sv2-bitcoin-corewithcargo run --example logger "/path/to/node.sock"ctrl+chere's stack trace:
ryanofsky commentedon Oct 7, 2025
This seems like a new crash I haven't seen before. Probably there is something the rust code could be doing differently to prevent the crash, but that wouldn't mean it is doing anything wrong, since the node should be able to avoid crashing on unclean shutdowns. Will look into this more and try to suggest changes and fix.
plebhash commentedon Oct 7, 2025
to be fair, the shutdown strategy on the rust code doesn't really do anything to try to be "clean"
when
ctrl+cis hit, we simply break the loops of every spawned task and drop everything from memory (including records to whateverwaitNextrequest that was still waiting for completion)plebhash commentedon Oct 7, 2025
also worth mentioning that the steps listed above are not able to reproduce it deterministically
sometimes it happens, sometimes it doesn't happen
probably related to the order in which things are dropped from memory, which I assume
capnpandcapnp-rpccrates take as triggers for IPC signals for resource cleanup on the server sideryanofsky commentedon Oct 8, 2025
Thanks @plebhash. The stack trace from #33554 (comment) shows the problem pretty clearly, and I created an issue to track it: bitcoin-core/libmultiprocess#226.
It looks to me like there's not way great way for the rust client to avoid this problem, and this is something
bitcoin-nodeshould be changed to fix by (1) fixing the abort described in bitcoin-core/libmultiprocess#226 and (2) improving the mining interface so there is a way to interruptwaitNextcalls.I think currently the only reliable way to avoid triggering the abort is to avoid disconnecting until
waitNextreturns.But this might be undesirable because there isn't currently a way to interrupt the waitNext call and have it return early. It would be good if
bitcoin-nodewould address this by adding a newBlockTemplateinterruptWaitmethod, or just haveBlockTemplatedestructor interrupt the wait. The client should have some clean way of interrupting thewaitNextcall if it no longer needs a new block so mining interface clients can shut down quickly and cleanly.plebhash commentedon Oct 8, 2025
I have a question related to the approach I started taking with the insights coming from the crashes reported here.
following your advice, I'm no longer using one single server thread for everything... now there's one "static" server thread that's responsible for all non-blocking calls (e.g.: fetching some template data or submitting solution to some template)
and for
waitNext, there's dedicated server thread(s)the thing is, I still need to cater for incoming Sv2
CoinbaseOutputConstraintsmessages, and whenever that arrives, I need to make sure theBlockTemplate(orTemplateIpcClientas I'm aliasing on the rust code) that's used to kickstart the nextwaitNextloops has the correctblock_reserved_weightandmax_additional_sigopsas defined on the Sv2 message.and since I cannot interfere with server thread dedicated to the ongoing
waitNext(because it would lead to crashes), I'm being forced to instantiate yet another server thread, just so I can instantiate the newBlockTemplatewith the new coinbase constraints and kickstart the newwaitNextloopso my question is: by doing this, am I risking unbounded resource consumption on
bitcoin-node? because basically I'm not taking any explicit steps to kill the server thread that was dedicated forwaitNextloops under the previous coinbase constraints... the reference toThreadIpcClientis simply dropped from memory, and that's it.anyways, once the changes mentioned on the comment above take place, this should no longer be a relevant issue, because as soon as
CoinbaseOutputConstraintsarrived, I'd be able to kill the currentwaitNextcall and simply use the same server thread for the new one, so the rust client would always be using only two server threads without any need for creating more server threads every time we had new coinbase constraintsbut I felt I should ask anyways, because it seems like an important concept that's still foggy on my mental model for IPC
ryanofsky commentedon Oct 8, 2025
These are good questions. I opened #33575 to figure out how to cancel waitNext calls, and I think it should not be hard to provide that.
More broadly, I think I'd try just having a c++ "waiter" thread dedicated to running
waitNextcalls, and a c++ "worker" thread to run all other IPC operations besideswaitNext. The "waiter" thread should be mostly blocked monitoring mempool and network, and the "worker" thread should be available to do anything else you might need like fetching and submitting block data.With current v30 code, there is no mechanism to cancel waitNext calls, so I think simplest approach would be to create a new c++ thread for each waitNext call, effectively having multiple "waiter" threads and one "worker" thread. This will use more resources, but I would not expect it to take a lot more, because presumably
block_reserved_weightandmax_additional_sigopsoption values should not change very frequently, and new blocks being connected should provide an upper limit on how long waitNext calls stick around.plebhash commentedon Oct 8, 2025
rephrasing my previous question in a more compact way:
is there a way to "kill" server threads?
indeed, I think this will be relatively rare in practice... but it's still something that's not under our control, and on the current strategy it will lead to unbounded resource consumption on Bitcoin Core side (unless server threads could be killed)
ryanofsky commentedon Oct 8, 2025
Indirectly, yes. The server threads will destroy themselves as soon as they are no longer referenced, either by the client or an ongoing IPC call that is using them. So as long as the client is not holding references to threads it is not using, they will be cleaned up.
There is some cost to creating threads, so it's good to reuse them between calls, and why I recommended having dedicated "waiter" and "worker" threads. But if you wanted to create more threads than that for different calls it would probably work ok in practice.
As long as there is no way to cancel waitNext calls, it could lead to a lot of threads being created if you need to make many calls. I'd just expect the number to be pretty limited based on how many should be needed. After cancellation is implemented you should be able to get away with having just 2 threads total.
plebhash commentedon Oct 8, 2025
ok I had AI tell me the same thing but didn't want to blindly trust it, so that's why I went out of my way to confirm that. Good to know.
then also what I said about unbounded resource consumption above is not true, since references to server threads for the old
waitNextloops are dropped.but still, ideally only 2 threads should be enough, and I guess we'll get there eventually.
plebhash commentedon Nov 17, 2025
@ryanofsky should we close this?
ryanofsky commentedon Nov 18, 2025
Thanks will close. The original issue where then node crashes when a client requests to multiple IPC calls to execute simultaneously on the same worker thread should be fixed by bitcoin-core/libmultiprocess#214 and #33519 which replaces the crashes with "thread busy" errors.
The crash reported later where killing the rust code in the middle of a waitNext call causes the node to crash during shutdown (#33554 (comment)) isn't fixed yet but I created a separate issue to track it bitcoin-core/libmultiprocess#226. Also the new
interruptWaitmethod in #33676 should make the problem less likely to happen if the rust client uses it.Will close this since remaining issue is tracked in bitcoin-core/libmultiprocess#226