Skip to content

Conversation

@ryanofsky
Copy link
Collaborator

The PR avoids errors from non-C++ rust & python clients when they make asynchronous requests (bitcoin/bitcoin#33923) and unclean disconnects (bitcoin/bitcoin#34250). Neither of these errors are easily possible to trigger from libmultiprocess clients because of its blocking interface and RAII semantics, but they are fairly easy to trigger from rust and python and there is a test triggering both of them in bitcoin/bitcoin#34284

If multiple IPC requests happen at the same time specifying same Context.thread
to run the requests on, queue the requests to execute in the order they are
received instead of raising a "thread busy" exception.

This change has no effect on C++ clients using libmultiprocess as a client
library, since the libmultiprocess client only makes blocking calls and creates
a server thread for every client thread, so it's not possible for there to be
multiple calls on the same server thread.

But this change may be useful for rust and python clients as discussed
bitcoin/bitcoin#33923
…erface pointer

This is a potential fix for bitcoin/bitcoin#34250
which reports that bitcoin node crashes if a rust stratrumv2 mining client
calls BlockTemplate.waitNext() and disconnects without waiting for a response
from the call, and if mempool fees increased so the call returns a non-null
interface BlockTemplate pointer.

The node would crash in this case while trying to call MakeProxyServer on the
returned BlockTemplate pointer, which would fail because MakeProxyServer would
try to use a reference to the Connection object that had been deleted as a as a
result of the disconnect.

The fix works by:

- Adding a Connection::m_canceler member variable and using it to cancel any
  IPC response promises that are pending when the connection is destroyed.

- Updating type-context.h PassField() function to use promise.attach() as
  described https://capnproto.org/cxxrpc.html#cancellation to detect
  cancellation and set a ServerContext::m_cancelled variable.

- Updating ServerCall to check the ServerContext::m_cancelled status after any
  C++ server method returns, and throw an exception if it is set.

- Updating type-context.h PassField() function to deal with the exception
  by catching and logging it, and to deal with cancelled status by not
  trying to fulfill the cancelled promise.
@DrahtBot
Copy link

DrahtBot commented Jan 21, 2026

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Reviews

See the guideline for information on the review process.
A summary of reviews will appear here.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #218 (Better error and log messages by ryanofsky)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

@ryanofsky
Copy link
Collaborator Author

Updated ba865d9 -> 92a2c5f (pr/promise.1 -> pr/promise.2, compare) fixing various ci errors (iwyu, compiler errors) https://github.com/bitcoin-core/libmultiprocess/actions/runs/21196838571

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.

2 participants