From 9f4bc29025287e8e12a7ef31c9918c1adfdfff5d Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Fri, 26 Jun 2026 13:50:23 -0700 Subject: Fix broadcast hanging forever on a stalled response MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The Esplora broadcast cleared its abort timer right after fetch() resolved, so the subsequent res.text() body read had no timeout — a stalled response body hung the whole broadcast (and the send spinner) indefinitely, with the tx never reaching the network. Keep the abort timer active through the body read, and add a hard 30s outer timeout in the send handler so a wedged broadcast always surfaces as 'timed out — try again' instead of spinning forever. (The silent-payment tx itself is valid — verified structure + BIP143 signature over the real outputs.) Co-Authored-By: Claude Opus 4.8 (1M context) --- src/api.js | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'src/api.js') diff --git a/src/api.js b/src/api.js index 1ab8c0a..6f010cb 100644 --- a/src/api.js +++ b/src/api.js @@ -336,19 +336,20 @@ export class Api { const attempts = this._hosts.map(async (host) => { const ctrl = new AbortController(); const timer = setTimeout(() => ctrl.abort(), this._timeoutMs); - let res; try { - res = await fetch(host.base + '/tx', { method: 'POST', body: hexTx, signal: ctrl.signal }); + // Keep the abort timer active across BOTH the request and the body read — + // a stalled response body must not hang the broadcast forever. + const res = await fetch(host.base + '/tx', { method: 'POST', body: hexTx, signal: ctrl.signal }); + const body = await res.text(); + if (res.status === 429) { + host.cooldownUntil = Date.now() + 30000; + this.#penalize(); + } + if (!res.ok) throw new Error(body || `${res.status} broadcast failed`); + return body.trim(); // txid } finally { clearTimeout(timer); } - const body = await res.text(); - if (res.status === 429) { - host.cooldownUntil = Date.now() + 30000; - this.#penalize(); - } - if (!res.ok) throw new Error(body || `${res.status} broadcast failed`); - return body.trim(); // txid }); const results = await Promise.allSettled(attempts); const ok = results.find((r) => r.status === 'fulfilled'); -- cgit v1.2.3