Address review: avoid the sendPayment timeout race, keep paymentLookup bounded

sendPayment's timeout_seconds defaults to 600, equal to the wrapper's
600 s transport bound, so the transport timer (started first) would
win the race and surface ECONNABORTED instead of LND's clean
FAILURE_REASON_* result. The call now passes timeout_seconds plus a
60 s margin as the per-call transport timeout, so LND's mapped failure
always arrives first while the transport stays bounded for the actual
hang case (and a user-supplied timeout_seconds scales the bound with
it).

paymentLookup (/v2/router/track) deliberately keeps the 10-minute
default: it holds a browser-facing response open while tracking, and
payments in flight longer than that are delivered by the websocket
subscription path instead. Documented at the call site.

Verified on the fixture: a routed payment with an explicit
timeout_seconds succeeds; an unroutable payment returns LND's mapped
failure reason (Insufficient Balance - no ECONNABORTED, no transport
timeout message); paymentLookup returns the final state of a settled
payment. Both API suites re-pass.
This commit is contained in:
saubyk 2026-07-19 16:22:11 -07:00 committed by Suheb
parent 19aa332d61
commit 89b6313a5b
2 changed files with 14 additions and 2 deletions

View file

@ -89,6 +89,9 @@ export const paymentLookup = (req, res, next) => {
return res.status(options.statusCode).json({ message: options.message, error: options.error });
}
options.url = req.session.selectedNode.settings.lnServerUrl + '/v2/router/track/' + req.params.paymentHash;
// Deliberately keep the wrapper's default timeout here: this holds a
// browser-facing response open while tracking, and payments in flight
// longer than that are delivered via the websocket subscription instead.
request(options).then((body) => {
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Payments', msg: 'Payment Information Received for ' + req.params.paymentHash, data: body });
res.status(200).json(body.result || body);
@ -111,7 +114,10 @@ export const sendPayment = (req, res, next) => {
req.body.timeout_seconds = req.body.timeout_seconds || 600;
options.form = JSON.stringify(req.body);
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Payments', msg: 'Send Payment Options', data: options.form });
request.post(options).then((body) => {
// LND ends the stream at timeout_seconds with a FAILURE_REASON_TIMEOUT result;
// give the transport a margin over that so LND's mapped failure always wins
// the race against the wrapper's own timeout.
request.post({ ...options, timeout: (+req.body.timeout_seconds + 60) * 1000 }).then((body) => {
const results = body.split('\n').filter(Boolean).map((jsonString) => JSON.parse(jsonString));
body = results.length > 0 ? results[results.length - 1] : { result: { status: 'UNKNOWN' } };
if (body.result.status === 'FAILED') {