Skip to content

subservers: report remote sub-server disconnects at runtime - #1373

Open
Vandit1604 wants to merge 11 commits into
lightninglabs:masterfrom
Vandit1604:644-remote-subserver-disconnect-status
Open

Vandit1604 wants to merge 11 commits into
lightninglabs:masterfrom
Vandit1604:644-remote-subserver-disconnect-status

Conversation

@Vandit1604

@Vandit1604 Vandit1604 commented Aug 13, 2026 •

Copy link
Copy Markdown
Contributor

Change

In remote mode, a sub-server that disconnected after startup was still reported as running by the status server, so litcli status kept showing it as healthy. Only failures during startup were tracked; a disconnect at runtime was not.

This adds a watcher on each remote sub-server's gRPC connection. When the connection drops (TransientFailure/Shutdown) the sub-server is marked errored, and when it recovers (Ready) it is marked running again, so the status server reflects the real runtime state.

Two smaller things came along with it:

  • Manager.Stop now also tears down remote sub-servers (it skipped them before), so the watcher and the remote connection are stopped on shutdown. The remote branch in stop() was effectively dead before, since remote servers never reached it.
  • status.SetErrored logged "could not start the X sub-server", which is wrong for a runtime disconnect, so the log is now neutral.

Note: the watcher nudges an idle connection with conn.Connect() so a disconnect is still observed when no requests are in flight. That keeps the remote connection warm rather than letting it idle out, which is the trade-off for observability here.

Scope

This is the first, smallest step towards #644, as suggested by @ViktorT-11: get the status reporting right before adding any reconnect/restart logic. It intentionally does not restart sub-servers or touch the lnd reconnect path.

Known gaps left as follow-ups:

  • Integrated pool/faraday expose no runtime error channel, so their disconnects are still not tracked.
  • Actually restarting the lnd-dependent sub-servers after a disconnect.
  • A remote server that is already down at connect time is briefly shown as running until the first failure transition (the connection is dialled lazily).

Testing

TestWatchRemoteConn starts a real gRPC backend, stops it, and asserts the disconnect is reported, then restarts it and asserts the recovery is reported.

Part of #644.

@litbot-9000

Copy link
Copy Markdown

@ViktorT-11: review reminder

2 similar comments
@litbot-9000

Copy link
Copy Markdown

@ViktorT-11: review reminder

@litbot-9000

Copy link
Copy Markdown

@ViktorT-11: review reminder

@Cyberguru1 Cyberguru1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great contribution, @Vandit1604 🙌

I’ve done a first-pass review and left a few comments below.

Comment thread subservers/subserver.go
// status server reflects a runtime disconnect instead of keeping the
// sub-server marked as running. The watcher stops when the sub-server is
// stopped.
func (s *subServerWrapper) watchRemoteConn(onError func(error),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be worth adding an isWatching flag to subServerWrapper to make watchRemoteConn idempotent. Checking this before starting the goroutine lets any extra calls exit early, so we avoid spawning duplicate goroutines and triggering duplicate error callbacks.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Comment thread subservers/subserver_test.go Outdated
Comment on lines +64 to +65
close(ss.quit)
ss.wg.Wait()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we switch this to require.NoError(t, ss.stop()) so we exercise the full teardown logic and close remoteConn properly.

Just like Name(), we will also need to add Remote() to nameOnlySubServer. When I tested ss.stop() locally without it, it panicked with a nil pointer dereference when stop() evaluated s.Remote().

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@Vandit1604
Vandit1604 force-pushed the 644-remote-subserver-disconnect-status branch 3 times, most recently from 0d217d5 to e46ad38 Compare September 18, 2026 20:19
@litbot-9000

ghost commented Sep 24, 2026

Copy link
Copy Markdown

@Vandit1604, remember to re-request review from reviewers when ready

@Vandit1604
Vandit1604 force-pushed the 644-remote-subserver-disconnect-status branch from e46ad38 to c919e71 Compare September 24, 2026 21:18
@Vandit1604

ghost commented Sep 24, 2026

Copy link
Copy Markdown
Contributor Author

Hi @Cyberguru1, thanks for the review! watchRemoteConn is idempotent now, and the test calls ss.stop() so the full teardown runs. Could you take another look whenever it suits you?

@litbot-9000

ghost commented Oct 1, 2026

Copy link
Copy Markdown

@ViktorT-11: review reminder
@Vandit1604, remember to re-request review from reviewers when ready

ghost left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work @Vandit1604 , the PR is almost in shape 🔥

Apologies for the late response 🙏

I ran some more tests after your fixes. Left a review below:

Comment thread subservers/subserver.go
}

s.wg.Add(1)
go func() {

ghost Oct 6, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we reset watching to false via defer in the goroutine? Otherwise if the subserver reconnects after the goroutine exits, it'd see true and skip starting a new watcher.

ghost Oct 6, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@Vandit1604

ghost commented Oct 6, 2026

Copy link
Copy Markdown
Contributor Author

While testing this round, I found that stop() on a remote sub-server whose dial failed fell through to the integrated Stop(). For pool, that panics at shutdown, because this PR now makes Manager.Stop stop remote sub-servers too. Fixed in 08c8ce9 and covered by TestManagerStopMixed.

@Cyberguru1 this is ready for another look when you have time.

@litbot-9000

ghost commented Oct 13, 2026

Copy link
Copy Markdown

@ViktorT-11: review reminder
@Vandit1604, remember to re-request review from reviewers when ready

@Vandit1604
Vandit1604 force-pushed the 644-remote-subserver-disconnect-status branch from 46ae104 to c8b4604 Compare October 14, 2026 03:26
@litbot-9000

ghost commented Oct 20, 2026

Copy link
Copy Markdown

@Vandit1604, remember to re-request review from reviewers when ready

ghost left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work, @Vandit1604! 🔥
LGTM, tACK.

This needs a rebase.

@Vandit1604
Vandit1604 force-pushed the 644-remote-subserver-disconnect-status branch from c8b4604 to bc06585 Compare October 26, 2026 19:48
@Vandit1604

ghost commented Oct 28, 2026

Copy link
Copy Markdown
Contributor Author

#1440 moved the quit/wg teardown in stop() into a defer, so after the rebase the remote conn closes before the watcher exits. The watcher then saw Shutdown and marked the sub-server as errored on every clean stop. It now returns on Shutdown, since only our own Close puts the conn in that state.

@Cyberguru1 this part changed after your approval. @ViktorT-11 ready for you too.

@litbot-9000

ghost commented Nov 4, 2026

Copy link
Copy Markdown

@ViktorT-11: review reminder

@Vandit1604
Vandit1604 force-pushed the 644-remote-subserver-disconnect-status branch from bc06585 to a018967 Compare November 5, 2026 01:01
@litbot-9000

ghost commented Nov 12, 2026

Copy link
Copy Markdown

@ViktorT-11: review reminder

@Vandit1604
Vandit1604 force-pushed the 644-remote-subserver-disconnect-status branch from a018967 to c53d952 Compare November 16, 2026 22:53
@litbot-9000

ghost commented Nov 23, 2026

Copy link
Copy Markdown

@ViktorT-11: review reminder

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.

3 participants