Skip to content

multi: bump loop+pool to lnd conn-ownership fix, document ownership model - #1458

Draft
litbot-9000 wants to merge 3 commits into
lightninglabs:masterfrom
litbot-9000:docs/subserver-conn-ownership
Draft

litbot-9000 wants to merge 3 commits into
lightninglabs:masterfrom
litbot-9000:docs/subserver-conn-ownership

Conversation

@litbot-9000

@litbot-9000 litbot-9000 commented Oct 30, 2026 •

Copy link
Copy Markdown

Refs #1381: fixes pinheadmz's remote-mode case, where every component dies within ms with grpc: the client connection is closing while lnd is healthy. It does not address the OP's integrated-mode 30s DeadlineExceeded, which is a separate bug, so the issue should stay open.

What

Integrated Loop and Pool closed LiT's shared *lndclient.GrpcLndServices whenever they stopped, gracefully or because of a runtime error. That tore down the connection every other component depends on: the macaroon service, tapd, faraday and accounts. The fix is in the sub-servers:

Both PRs make the borrowed connection non-closable by type. StartAsSubserver now takes *lndclient.LndServices, which has no Close, instead of the closable wrapper. This is an intentional breaking API change. This PR is the litd side:

  1. Dep bump. Pins loop and pool to the fix via replace directives, so litd builds and CI runs against it now.
  2. Call sites. subservers/loop.go and subservers/pool.go pass &lndGrpc.LndServices.
  3. Docs. Adds docs/subserver-connection-ownership.md with the ownership model, the lifecycle and the rules, plus a new release-notes-0.17.11.md because v0.17.10 is already tagged.

litd itself needs no ownership change. It already closes the shared connection exactly once, in shutdownSubServers, after subServerMgr.Stop(). Faraday and tapd are untouched: Faraday already has lndOwned, and tapd never receives the wrapper.

Why replace to backport branches (not the PR heads)

Pool master has already migrated to btcd v2 modules (lightninglabs/pool#524), and litd hasn't. Pinning pool master pulls in btcd v0.26.0, and go mod tidy then fails on litd's own btcd/{chaincfg,wire,txscript} imports. To keep this PR to the fix, I cherry-picked the two fix commits from each PR onto the release tags litd already pins. Nothing else changed apart from dropping release-note hunks that didn't apply:

module base branch commit
loop v0.35.2-beta litbot-9000/loop@fix/lnd-conn-ownership-v0.35.2 d72d75fb1ca1
pool v0.7.2-beta litbot-9000/pool@fix/lnd-conn-ownership-v0.7.2 5b777bbd9744

The ownership tests (-run Ownership) pass on both backports. Before merge: cut loop v0.35.3-beta and pool v0.7.3-beta (or equivalent) from these branches, then swap the replace lines for normal require bumps. Draft until then.

Ownership model

flowchart TD
    subgraph LIT["lightning-terminal (litd) — OWNER"]
        CREATE["setupFullLNDClient()<br/>creates the single shared<br/><b>*lndclient.GrpcLndServices</b><br/>(closable wrapper)"]
        SHUTDOWN["shutdownSubServers()<br/>stops all sub-servers first,<br/>then closes the shared conn<br/><b>exactly once</b>"]
    end

    subgraph SUBSERVERS["integrated sub-servers — BORROWERS"]
        FARADAY["Faraday<br/>reference model:<br/>lndOwned tracking"]
        LOOP["Loop<br/>StartAsSubserver(<br/>*lndclient.LndServices)"]
        POOL["Pool<br/>StartAsSubserver(<br/>*lndclient.LndServices)"]
        TAPD["tapd<br/>never receives the wrapper"]
    end

    LND[("remote or integrated lnd")]

    CREATE -- "gRPC conn + subserver clients" --> LND
    CREATE -- "borrowed non-closable view<br/>(*lndclient.LndServices)" --> LOOP
    CREATE -- "borrowed non-closable view" --> POOL
    CREATE -- "borrowed view<br/>(lndOwned=false)" --> FARADAY
    CREATE -- "services only" --> TAPD

    LOOP -. "must never close<br/>(type-level: no Close in scope)" .-> LND
    POOL -. "must never close<br/>(type-level: no Close in scope)" .-> LND
    SHUTDOWN -- "the ONLY Close()<br/>on the shared conn" --> LND
Loading
stateDiagram-v2
    [*] --> ConnAlive: litd creates shared GrpcLndServices
    ConnAlive --> SubserversRunning: litd injects borrowed view<br/>via StartAsSubserver
    SubserversRunning --> SubserverStopped: a sub-server stops<br/>(graceful or runtime error)
    SubserverStopped --> SubserversRunning: other sub-servers keep<br/>using the SAME conn
    SubserversRunning --> ConnClosed: litd shutdownSubServers()<br/>after ALL sub-servers stopped
    ConnClosed --> [*]
Loading

Invariant: a sub-server stopping must not close the shared connection. Before the fix, loop and pool violated it.

Verification

  • go build -tags="litd_no_ui $(LND_RELEASE_TAGS)" ./... passes, go vet ./subservers/ passes, and go test ./subservers/ passes.
  • The loop and pool PRs each guard the invariant three ways: the type change, bufconn regression tests (shown failing on pre-fix code), and an AST guard test that fails on any .Close() of a borrowed handle.
  • An independent review of loop#1272 and pool#528 found no blocking issues. The nits are listed there.
  • loop CI's advisory "run LiT …" jobs fail against litd master with exactly the StartAsSubserver type error. That is expected, and it goes away once this PR lands.

Add an authoritative reference page for the connection-ownership
relationship between litd and its integrated sub-servers: litd creates
and owns the single shared *lndclient.GrpcLndServices and closes it
exactly once in shutdownSubServers; integrated sub-servers receive a
borrowed, non-closable view via StartAsSubserver and must never close
it.

Includes mermaid diagrams of the ownership relationship and the
connection lifecycle, the failure mode behind the remote-lnd report
in lightninglabs#1381 (comment 6530026672), and the verification layers
(type-level prevention, regression tests, static guards) that keep
this bug class from silently recurring.

Refs lightninglabs#1381 (comment 6530026672).
Refs lightninglabs#1329 (comment 6530856512).
@litbot-9000
litbot-9000 force-pushed the docs/subserver-conn-ownership branch from 23698d0 to ec2f2f7 Compare October 30, 2026 22:57
@litbot-9000 litbot-9000 changed the title docs: document sub-server lnd connection ownership model multi: bump loop+pool to lnd conn-ownership fix, document ownership model Oct 30, 2026
@litbot-9000
litbot-9000 marked this pull request as draft October 30, 2026 22:57
claudell added 2 commits October 31, 2026 01:19
Pin loop and pool to the connection-ownership fix from loop#1272 and
pool#528, backported onto the currently pinned v0.35.2-beta and
v0.7.2-beta releases. The replace directives are to be swapped for
tagged releases before merge.

The fix makes StartAsSubserver take the non-closable
*lndclient.LndServices view instead of the closable
*lndclient.GrpcLndServices wrapper, so an integrated Loop or Pool can no
longer close LiT's shared lnd connection when it stops. Update both call
sites to hand over the borrowed view; LiT remains the sole owner and
closes the connection once in shutdownSubServers.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant