Skip to content

sv2-tp: reconnect to bitcoin core IPC after disconnect#101

Open
enirox001 wants to merge 5 commits intostratum-mining:masterfrom
enirox001:reconnect-subtree-clean-series
Open

sv2-tp: reconnect to bitcoin core IPC after disconnect#101
enirox001 wants to merge 5 commits intostratum-mining:masterfrom
enirox001:reconnect-subtree-clean-series

Conversation

@enirox001
Copy link
Copy Markdown

@enirox001 enirox001 commented May 4, 2026

This PR makes sv2-tp recover from a lost ipc connection without dropping the process.

The first commit fixes a libmultiprocess teardown race during client proxy destruction. A proxy can still hold a non-null Connection* after disconnect handling has started, and calling the generated destroy() method in that window can raise an IPC disconnect exception during ordinary destruction. Mark the connection as disconnected as soon as teardown begins and skip best-effort remote destroy calls once that state is reached.

With that in place, sv2-tp can reconnect cleanly in-process. Keep the template provider and pool-facing connection manager alive across backend loss, reconnect to Bitcoin Core with backoff, install a fresh IPC backend, and resume serving templates on the existing pool connection.

The final cleanup commit removes the reconnect-time workarounds that were only needed before the IPC teardown fix. Backend ownership returns to normal unique_ptr use, and shutdown returns to the normal process path.

It also adds explicit exception handling around IPC method calls (like waitNext and submitSolution) to ensure the template provider gracefully traps disconnect errors without crashing

@enirox001 enirox001 changed the title sv2-tp: reconnect to Bitcoin Core IPC after disconnect sv2-tp: reconnect to bitcoin core IPC after disconnect May 4, 2026
@enirox001 enirox001 force-pushed the reconnect-subtree-clean-series branch 4 times, most recently from 20b5772 to 79e0653 Compare May 6, 2026 09:01
enirox001 added 5 commits May 6, 2026 10:55
Client proxy destruction can race with connection teardown.

When a remote disconnect begins, a proxy may still hold a non-null
connection pointer before synchronous cleanup callbacks have cleared
client state. In that window, calling the generated destroy() method
can raise an IPC disconnect exception during ordinary proxy
destruction.

Add an explicit connection teardown flag and skip best-effort remote
destroy calls once disconnect handling has started.
Add a reconnect loop around the initial Bitcoin Core IPC setup.

When the IPC connection cannot be established, retry with exponential
backoff instead of exiting immediately. This provides the basis for
recovering sv2-tp after backend loss.
Decouple the template provider lifetime from the Bitcoin Core IPC
backend.

Keep the Stratum v2 listener and connected clients alive when the
backend disconnects, wait for a replacement backend, and resume
serving templates once a new IPC connection is installed.
Adapt the sv2 template provider tests to the reconnect lifecycle.

Construct the provider without a fixed Mining reference and install the
backend through the new reconnect path so the test harness matches the
runtime behavior.
Simplify the reconnect implementation now that disconnected proxy
teardown is handled in the IPC layer.

Remove the local teardown workarounds, restore ordinary backend
ownership, and harden the remaining shutdown path so reconnect and
operator shutdown both complete cleanly.
@enirox001 enirox001 force-pushed the reconnect-subtree-clean-series branch from 79e0653 to 8f0ba30 Compare May 6, 2026 09:57
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.

1 participant