Skip to content

plugin: Track whether a signer is answering right now - #776

Open
cdecker wants to merge 1 commit into
mainfrom
2026m11-signer-presence
Open

cdecker wants to merge 1 commit into
mainfrom
2026m11-signer-presence

Conversation

@cdecker

@cdecker cdecker commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator

Summary

Dialling a peer while no signer answers freezes connectd: its ECDH is a blocking hsmd call on its only thread. The plugin had no signal to avoid that. SIGNER_COUNT only drops when a send fails, so a backgrounded app with a half-open stream still counts as attached.

The Stage now tracks signer presence, a watch that can go back to Silent:

Silent ──first reply after attach (incl. error replies)──▶ Answering
Answering ──last stream detaches──────────────────────────▶ Silent
Answering ──request unanswered > 10 s──────────────────────▶ Silent
             (counted from max(staged, last reply), so a fresh
              signer isn't blamed for the backlog it inherits)

The dial gate that callers ask right before each connect:

check_answering()
  no stream attached           -> Silent (no probe)
  reply within 10 s            -> Answering (no probe)
  else stage a GetHeartbeat probe (id in 1..=999, below hsmproxy's 1000+)
       shared by concurrent callers, 5 s timeout
       reply   -> Answering
       timeout -> Silent, probe removed from the stage
await_answering(within)        -> waits for the gate to say Answering

Also:

 stuck_request_types
+  1  // WIRE_HSMD_ECDH: freezes all of connectd
 stream_hsm_requests loop
-  next = stream.next()            // noticed a gone signer on the next send
+  select { stream.next(), tx.closed() => break }
 respond_hsm_request
+  stage.note_reply()              // before the error early-return

Evidence

New unit tests in stager.rs, run with paused tokio time (cargo test -p gl-plugin --lib stager, 13 passed):

  • attach, then reply → Answering
  • request outstanding for 11 s → Silent; at 9 s still Answering
  • backlog that is 60 s old when the signer attaches → stays Answering until 10 s without a reply
  • last stream drops → Silent; a late reply from a detached signer doesn't revive it
  • fresh reply → no probe staged
  • no signer → Silent at once
  • half-open stream → probe times out after exactly 5 s → Silent, probe cleared
  • two concurrent callers → one shared GetHeartbeat probe
  • await_answering returns when a signer attaches, or false at the deadline
  • an unanswered ECDH reports stuck

Merge Danger

Door: two-way

Additive API on Stage. Nothing in this crate dials through the gate yet. The internal plugin adopts it in a separate change.

Blast Radius: small

  • Probes are only sent when a caller asks the gate. They are ordinary GetHeartbeat requests, the same as the one sent on attach.
  • Nodes with an unanswered ECDH now report stuck, which can affect scheduler decisions that use that flag.
  • tokio test-util is a dev-dependency only.

Dialling a peer while no signer answers freezes connectd: its ECDH is
a blocking hsmd call on its single thread, which stalls all peer I/O
until a signer replies. The plugin had no signal to avoid that: the
signer count only drops when a send fails, so a backgrounded app with a
half-open stream still counts as attached.

The stage now tracks signer presence, Answering or Silent, as a watch
that can go back to Silent. A signer is Answering after its first reply
following an attach, including error replies. It is Silent once its
stream exits, or once a request has gone unanswered for 10 s, counted
from the later of staging and the last reply, so a freshly attached
signer is not blamed for the backlog it inherits.

`check_answering` is the dial gate: a reply within 10 s answers at
once, otherwise it stages a GetHeartbeat probe (ids below hsmproxy's
range) and waits up to 5 s; concurrent callers share one probe.
`await_answering` waits for a signer within a deadline.

ECDH joins the stuck request types, and the request stream task now
ends as soon as the signer drops the stream.

This branch has not been deployed

No deployments
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