Files
amethyst/desktopApp/src/jvmMain
Vitor PamplonaandClaude Opus 5 17609acc1e fix: keep the LNURL body read off the UI thread and bound its size
SendDialog's two LNURL effects returned the Response out of their
withContext(Dispatchers.IO) block and then called response.body.string()
outside it. body.string() is a blocking socket read and LaunchedEffect resumes
on the composition dispatcher, so the read ran on the EDT — the withContext
gave the appearance of off-thread IO while doing almost none of it, since the
cost of a request is mostly the body transfer. A slow or hostile LNURL server
froze the wallet dialog.

The Response was also never closed with use { }. On the happy path
body.string() closes the source itself, but both effects are keyed on
sendState and restart on every state change, so a cancellation between the
headers arriving and the body read leaked the connection.

Both effects now share fetchLnurlJson(), which does the request, the capped
body read and the parse inside one withContext(Dispatchers.IO) and always
closes the Response.

Adds the two missing guards:

- Size cap. LUD-06/LUD-16 documents are a few hundred bytes and the body is
  buffered in memory, so it is capped at 64 KiB. Note this does NOT copy
  Nip11Fetcher's pattern, which does not work: okio's readUtf8() is
  buffer.writeAll(source) + readUtf8(), and writeAll drains the entire
  upstream, so request(MAX) only pre-buffers and never limits the read. With a
  1 MB source and a 1 KB "cap" that pattern returns all 1,000,000 bytes.
  Reading from source.buffer after request(MAX + 1) caps for real.
  Nip11Fetcher has the same latent bug and is left for a separate change.

- Status code. Not a hard isSuccessful gate: LUD-06 servers report failures as
  HTTP 200 + {"status":"ERROR","reason":...} and some use 4xx with a usable
  reason body, so throwing before parsing would discard the server's message.
  The body is parsed first and the status is surfaced only when the body is
  not usable JSON — which is the HTML-error-page case that previously produced
  a raw Jackson error.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-12 19:01:24 -04:00
..