Harden API against downed lightning node#38
Closed
Copilot wants to merge 3 commits into
Closed
Conversation
…e server Agent-Logs-Url: https://github.com/damus-io/api/sessions/49edca8a-52fd-4a6b-8835-4821190f5c17 Co-authored-by: danieldaquino <24692108+danieldaquino@users.noreply.github.com>
…uter catch Agent-Logs-Url: https://github.com/damus-io/api/sessions/49edca8a-52fd-4a6b-8835-4821190f5c17 Co-authored-by: danieldaquino <24692108+danieldaquino@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix API crash caused by downed lightning node
Harden API against downed lightning node
May 20, 2026
Collaborator
|
Superseded by #40 |
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.
A downed LN node caused
ECONNREFUSEDto surface as an unhandled socket'error'event, crashing the entire server process. A secondary bug incheck_invoice_is_paid— thenew Promise(async ...)anti-pattern — letln_rpcrejections escape as unhandled promise rejections, also fatal in Node.js v15+.Fixes
src/index.js— Globalprocess.on('uncaughtException')andprocess.on('unhandledRejection')handlers as last-resort safety nets; logs the error and keeps the process alivesrc/invoicing.js— Rewrotecheck_invoice_is_paidto eliminate thenew Promise(async ...)anti-pattern:timer.unref()on the timeout so it doesn't block process exit.src/router_config.js— Added missingtry/catchtoPOST /ln-checkout/:id/check-invoiceandPUT /admin/ln-checkout/new-verified-checkout; added Express error-handling middleware ((err, req, res, next)) at the end ofconfig_routeras a final catch-all for unhandled route errorsTests
MockLNNodeControllerwithsimulate_node_down()/simulate_node_up()that causesconnect_and_initto rejectLN Flow — Downed LN node does not crash the servercovering: verify-checkout with node down (→ 400), check-invoice with node down (→ 200 withpaid: undefined), background poll with node down (no throw), and server still responsive after all failures