Repository navigation
fix: add timeout to payment status polling loop - #55
Open
lucianocasalunga wants to merge 1 commit into
Open
lucianocasalunga wants to merge 1 commit into
lucianocasalunga wants to merge 1 commit into
Conversation
The `_process_invoice` function polls LNbits for payment confirmation in a `while` loop with exponential backoff (max 60s per interval). If the underlying node never transitions a payment from pending to success/failed — e.g. due to mission-control poisoning, LND internal state corruption, or a node restart — the loop runs indefinitely, blocking the entire NWC request queue (which is processed serially). Adds a `PAYMENT_STATUS_POLL_TIMEOUT_SECONDS = 90.0` constant and a deadline check inside the loop. After 90 seconds the request returns an `INTERNAL` error instead of hanging forever. The timeout is configurable via the constant. This was observed in production: a poisoned LND mission-control cache caused `check_transaction_status` to always return `pending`, which blocked all subsequent NWC pay_invoice requests until the container was manually restarted. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The
_process_invoicefunction polls LNbits for payment confirmation in awhileloop with exponential backoff (max interval: 60 s). If the underlying Lightning node never transitions a payment from pending to success or failed — e.g. due to LND mission-control cache poisoning, a hung HTLC, or an internal node state issue — the loop runs indefinitely.Because NWC requests are processed serially inside the
ws.recv()loop, one stuck payment blocks all subsequentpay_invoicerequests until the process is manually restarted.Observed scenario
LND's mission-control cache poisoned a route to a destination node.
check_transaction_statuskept returningpending(the payment was never forwarded — 0 HTLCs attempted). The NWC worker blocked for the entire duration of the process lifetime.Fix
Adds a
PAYMENT_STATUS_POLL_TIMEOUT_SECONDS = 90.0constant and a deadline check inside the polling loop. After 90 seconds of waiting for a pending payment, the function returns anINTERNALerror instead of blocking forever. The timeout constant is easily adjustable.Notes
PAYMENT_FAILEDbranch (added in a prior fix) already handles the case where LND explicitly marks a payment as failed. This PR handles the complementary case where LND never marks it at all.PAYMENT_STATUS_POLL_TIMEOUT_SECONDSas needed.