Skip to content

test: wait for lnd's server before tests stop lnd - #295

Merged
prusnak merged 1 commit into
bitcoinix:masterfrom
ostermayer:test-lnd-server-active
Nov 20, 2026
Merged

prusnak merged 1 commit into
bitcoinix:masterfrom
ostermayer:test-lnd-server-active

Conversation

@ostermayer

@ostermayer ostermayer commented Nov 19, 2026 •

Copy link
Copy Markdown
Collaborator

netnsRegtest failed once on #291 because lnd panicked. lnd-wallet-init stopped lnd right after a new wallet came up, and lnd crashed on that early stop with unable to subscribe to chans: subscription server shutting down. lnd-restart-on-clean-exit then found the failed exit in lnd's journal.

lnd answers RPCs and notifies systemd before its server has started all subsystems, so neither lncli getinfo nor systemctl start closes that window. This PR:

  • adds wait_for_lnd_server to test/suite/helpers.py. When the regtest fixture has mined blocks (num_blocks), it waits until lncli state reports SERVER_ACTIVE. lnd starts its server only once its chain has synced. Without these blocks, as on the test mainnet, lnd never starts its server and can't panic this way, so the helper keeps the getinfo wait there. The fixture's data doesn't change when a run selects a subset of the tests.
  • uses it in the tests that run before lnd-restart-on-clean-exit and stop, restart or terminate lnd. These are config-replace, lnd-wallet-init and rtl-stops-with-backend.
  • also waits before restart-bitcoind and config-replace stop bitcoind, because lnd requires bitcoind and stops with it. Both start lnd before that wait, because lnd can be down there. restart-bitcoind reads whether lnd is enabled from a new test.data.restart-bitcoind.lnd, so this also works when a run leaves out test lnd.
  • tells test authors about the helper in test/README.md.

Testing

  • netnsRegtest and default pass on a KVM host. In the netnsRegtest log, the SERVER_ACTIVE wait comes right before each stop of bitcoind in restart-bitcoind and config-replace.
  • These focused runs on regtestBase with lnd also pass.
    • lnd-wallet-init alone. All three of its waits use lncli state.
    • config-replace alone, with lnd down when the test starts.
    • restart-bitcoind and lnd-restart-on-clean-exit, without test lnd. Both stops of bitcoind wait for SERVER_ACTIVE. Right after boot, the first wait took about 2.5 s, so the stop used to land in that window.
  • The panic is a race, so I can't trigger it on demand.

lnd-macaroon-revocation runs after lnd-restart-on-clean-exit and has its own failure check, so I left its stops of lnd for a separate change. lnd-create-macaroons also restarts lnd right after a start once it deletes stale root keys. Only a module change can close that window, and that wait needs a timeout, because a node that's still syncing never starts its server. backups stops bitcoind too, but it runs only on the test mainnet.

Written with Claude Opus 5.5, reviewed with Claude Fable 5.2.

@ostermayer ostermayer added the type: maintenance No user-visible change: refactor, CI, deps, tooling, docs-only label Nov 19, 2026
@github-actions github-actions Bot added the area: ci .github/, test/, dev/ label Nov 19, 2026
@prusnak prusnak added this to the v0.2.0 milestone Nov 19, 2026

@viberaven viberaven 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.

Waiting for SERVER_ACTIVE covers the direct wallet stop in the full netnsRegtest scenario. I found two paths where the tests can still stop lnd during server startup. The nine runner tests passed locally, and the PR’s default and netnsRegtest VM jobs passed.

Comment thread test/suite/restarts.py Resolved
Comment thread test/suite/helpers.py Resolved
@prusnak prusnak added the status: changes needed Cannot proceed until suggested changes are implemented label Nov 19, 2026
@ostermayer
ostermayer force-pushed the test-lnd-server-active branch from 1c73c0b to d8f78fe Compare November 20, 2026 12:17
@github-actions github-actions Bot added the area: docs docs/, README, examples/, SECURITY.md, book.toml, assets label Nov 20, 2026
@ostermayer

Copy link
Copy Markdown
Collaborator Author

Thanks, you're right on both. Both are fixed in d8f78fe.

  • config-replace now starts lnd and waits for its server right before each systemctl stop {unit} for bitcoind and lnd, in both symlink iterations, when the scenario has lnd. It starts lnd first because the wait needs a running lnd, and lnd can be down or still starting there. This replaces the waits after the starts. restart-bitcoind stops bitcoind the same way, so it now waits before both of its bitcoind stops, and rtl-stops-with-backend waits before its systemctl restart lnd too. In the netnsRegtest log the SERVER_ACTIVE wait now comes right before each bitcoind stop. config-replace alone with lnd down at the start passes as well.
  • wait_for_lnd_server now picks the wait from the fixture's num_blocks, not from enabled_tests. lnd only starts its server once its chain has synced, and that needs the mined blocks. restart-bitcoind reads whether lnd is enabled from a new test.data.restart-bitcoind.lnd, so it keeps its waits when a run leaves out test lnd. I ran lnd-wallet-init alone on regtestBase like you did, and all three waits used lncli state. The first two took about 2.5 s each, so the old stops came before lnd's server was up.

netnsRegtest and default pass on a KVM host, and so do the runner tests, module-config and shellcheck. lnd-macaroon-revocation still has the window. lnd-create-macaroons restarts lnd right after a start there too, and only a module change can fix that, so I left that test for a separate change.

@ostermayer
ostermayer requested a review from viberaven November 20, 2026 12:17

@viberaven viberaven 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.

Approved d8f78fe7. I reran both cases on KVM. With lnd initially down, config-replace started it and waited for SERVER_ACTIVE before each bitcoind stop and each direct lnd stop. Running lnd-wallet-init alone on regtestBase also passed, and all three waits used lncli state.

The CI logs confirm that restart-bitcoind waits before both the stop and the restart on netnsRegtest, and the default VM still uses getinfo. Regtest VM log · Default VM log

Both earlier findings are fixed. GitHub denied my requests to resolve the conversations with this read-only account. The PR author or a maintainer can close them. Bitcoind stop · Focused regtest run

Tests waited for lnd with `lncli getinfo` or `systemctl start`. lnd answers
RPCs and notifies systemd before its server has started all subsystems. On
regtest, a stop or SIGTERM in that window can make lnd panic ("unable to
subscribe to chans: subscription server shutting down"). The failed exit
then fails `lnd-restart-on-clean-exit`, which checks that lnd never failed
during the boot. This happened in `lnd-wallet-init`, which stops lnd right
after a new wallet comes up.

Add `wait_for_lnd_server`, which waits for `lncli state` to report
SERVER_ACTIVE when the regtest fixture has mined blocks (`num_blocks`). lnd
starts its server only once its chain has synced. Without these blocks, as
on the test mainnet, lnd never starts its server and can't panic this way,
so the helper keeps the `getinfo` wait. The fixture's data stays the same
when a run selects a subset of the tests.

Use it in the tests that run before that check and stop, restart or
terminate lnd: `config-replace`, `lnd-wallet-init` and
`rtl-stops-with-backend`. lnd requires bitcoind and stops with it, so
`restart-bitcoind` and `config-replace` also wait before they stop
bitcoind. Both start lnd before that wait, because lnd can be down there,
for example when a run leaves out test `lnd`. `restart-bitcoind` reads
whether lnd is enabled from a new `test.data.restart-bitcoind.lnd`.

`lnd-macaroon-revocation` runs after that check and has its own, so its
stops of lnd are left for a separate change. `lnd-create-macaroons` also
restarts lnd right after a start once it deletes stale root keys, and only
a module change can close that window. `backups` stops bitcoind before the
check too, but it runs only on the test mainnet.

Also tell test authors about the helper in `test/README.md`.

Assisted-by: Claude Code (Claude Opus 5.5)
@prusnak
prusnak force-pushed the test-lnd-server-active branch from d8f78fe to c9ecbe6 Compare November 20, 2026 14:11
@prusnak
prusnak enabled auto-merge November 20, 2026 14:11
@prusnak
prusnak merged commit cbc2310 into bitcoinix:master Nov 20, 2026
22 checks passed
@ostermayer ostermayer removed the status: changes needed Cannot proceed until suggested changes are implemented label Nov 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: ci .github/, test/, dev/ area: docs docs/, README, examples/, SECURITY.md, book.toml, assets type: maintenance No user-visible change: refactor, CI, deps, tooling, docs-only

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants