Skip to content

lndinit: use an exp backoff instead of connectionRetryInterval - #72

Merged
djkazic merged 1 commit into
lightninglabs:mainfrom
djkazic:backoff-subscribestate
Oct 8, 2025
Merged

djkazic merged 1 commit into
lightninglabs:mainfrom
djkazic:backoff-subscribestate

Conversation

@djkazic

@djkazic djkazic commented Oct 7, 2025 •

Copy link
Copy Markdown
Collaborator

Today, when using lndinit with litd via its built-in gRPC proxy, a peculiar issue can arise.

The root cause of this has to do with how gRPC requests for the StateService RPC are proxied. litd forwards these requests unconditionally regardless of LND's state as a subserver.

Because lndinit determines readiness by the state of the connection, this means that as soon as a valid gRPC connection exists, it will try to subscribe to LND's state. This is problematic for several reasons.

LND takes a few moments to startup, so lndinit will spam litd with SubscribeState requests; after all, the gRPC proxy doesn't know where to forward these requests.

Not only does this pollute the logs of litd, it also incurs a measurable CPU cost. Because the wait is a fixed 250 milliseconds, the severity is compounded with the more litd instances you run on a single machine.

This PR introduces a replacement to the fixed 250 ms ticker.

retryDelay is a calculated wait duration fed by the new function nextBackoff, which implements a simple 2x backoff. The maximum wait duration is capped at 10 seconds.

@djkazic
djkazic requested a review from Roasbeef October 7, 2025 12:21
@djkazic djkazic self-assigned this Oct 7, 2025
@djkazic
djkazic requested a review from JLSchuler99 October 7, 2025 12:21
@ZZiigguurraatt

Copy link
Copy Markdown
Contributor

please rebase so I can test with other commits on the main branch

@ZZiigguurraatt

Copy link
Copy Markdown
Contributor
image

@ZZiigguurraatt

Copy link
Copy Markdown
Contributor

please rebase so I can test with other commits on the main branch

OK, did that here: https://github.com/ZZiigguurraatt/lndinit/tree/backoff-subscribestate

@djkazic
djkazic force-pushed the backoff-subscribestate branch from 1abfe05 to bbcd1b6 Compare October 7, 2025 21:02
@ZZiigguurraatt

Copy link
Copy Markdown
Contributor

OK, I've fixed all the issues I was having that would trigger this, so I'm not really able to further test this PR, but it was working okay for me as I was tracing down the trigger issues.

So, I think it is probably good enough to merge.

@djkazic
djkazic merged commit c1fcd7c into lightninglabs:main Oct 8, 2025
@djkazic
djkazic deleted the backoff-subscribestate branch October 8, 2025 14:11
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