Fix missing user invoice timeout (#1379)

* Wait max 10 seconds for user wallet to create invoice

* Add timeout in error message
This commit is contained in:
ekzyis 2024-09-09 00:16:52 +02:00 committed by GitHub
parent 2ad2cabb03
commit 8c56904094
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 7 deletions

View File

@ -133,7 +133,7 @@ function timeoutPromise (timeout) {
// if no timeout is specified, never settle
if (!timeout) return
setTimeout(() => reject(new Error('timeout')), timeout)
setTimeout(() => reject(new Error(`timeout after ${timeout / 1000}s`)), timeout)
})
}

View File

@ -9,6 +9,7 @@ import walletDefs from 'wallets/server'
import { parsePaymentRequest } from 'ln-service'
import { toPositiveNumber } from '@/lib/validate'
import { PAID_ACTION_TERMINAL_STATES } from '@/lib/constants'
import { withTimeout } from '@/lib/time'
export default [lnd, cln, lnAddr, lnbits, nwc, phoenixd]
const MAX_PENDING_INVOICES_PER_WALLET = 25
@ -73,12 +74,13 @@ export async function createInvoice (userId, { msats, description, descriptionHa
throw new Error('wallet has too many pending invoices')
}
const invoice = await createInvoice({
const invoice = await withTimeout(
createInvoice({
msats,
description: wallet.user.hideInvoiceDesc ? undefined : description,
descriptionHash,
expiry
}, walletFull[walletField])
}, walletFull[walletField]), 10_000)
const bolt11 = await parsePaymentRequest({ request: invoice })
if (BigInt(bolt11.mtokens) !== BigInt(msats)) {