Bounty
XE-0934 · Bounty

SDK per-request timeout does not cover the response-body read

Triaging claimed Minor web filed 2026-11-06 18:47 UTC by byfor8

Report

Summary

XeClient is supposed to bound every HTTP call with timeoutMs so a stuck peer cannot pin a job. At sdk/src/client.ts:164-182, #once attaches AbortSignal to fetch, then clearTimeout(timer) in a finally after headers return, then await res.text() with no remaining deadline. A peer that answers headers and never finishes the body therefore hangs past the configured timeout: with timeoutMs=250 the request was still pending at 1003 ms, while a control fast body completed in 40 ms. Any SDK request() to a node or provider URL takes this path. GitHub #44 is sync page OOM; this is the SDK HTTP client dropping the deadline before the body read.

Affected components

sdk/src/client.ts:164-182 XeClient #once (AbortSignal cleared after headers, res.text() unbounded) at sdk 0dbc92ecff709bee79768e4e37788c682a0f4525.

Impact

A peer that answers headers and never finishes the body pins the caller's job for as long as the process lives. A call that should fail in 250 ms was still pending at 1003 ms. No data corruption; the hang is the whole impact.

PoC

#!/usr/bin/env node
/** A5 — per-request timeout does not cover the response-body read. */
import { XeClient } from './sdk.mjs'

const PIN = '0dbc92ecff709bee79768e4e37788c682a0f4525'
const TIMEOUT_MS = 250
console.log(`PROVENANCE: sdk=${PIN} file=poc/round3/a5_timeout_body.mjs timeoutMs=${TIMEOUT_MS}`)

function hangingFetch() {
  return async (url, init) => {
    const stream = new ReadableStream({
      start() {
        /* headers ready, body never arrives */
      },
    })
    return new Response(stream, { status: 200, headers: { 'content-type': 'application/json' } })
  }
}

function fastFetch(body) {
  return async () => new Response(body, { status: 200, headers: { 'content-type': 'application/json' } })
}

const ctrl = new XeClient({ url: 'http://127.0.0.1', timeoutMs: TIMEOUT_MS, retries: 0, fetch: fastFetch('{"ok":true}') })
const t0 = Date.now()
const ctrlBody = await ctrl.request('/ok')
const ctrlMs = Date.now() - t0
console.log(`CONTROL fast body ms=${ctrlMs} body=${JSON.stringify(ctrlBody)}`)

const atk = new XeClient({ url: 'http://127.0.0.1', timeoutMs: TIMEOUT_MS, retries: 0, fetch: hangingFetch() })
const waitMs = TIMEOUT_MS * 4
const t1 = Date.now()
const raced = await Promise.race([
  atk.request('/stall').then(
    (v) => ({ done: 'resolved', v, ms: Date.now() - t1 }),
    (e) => ({ done: 'rejected', v: String(e), ms: Date.now() - t1 }),
  ),
  new Promise((r) => setTimeout(() => r({ done: 'still_pending', v: null, ms: Date.now() - t1 }), waitMs)),
])
console.log(`ATTACK hang-body after ${waitMs}ms: ${JSON.stringify(raced)}`)

if (ctrlBody && ctrlBody.ok === true && raced.done === 'still_pending' && raced.ms >= waitMs - 20) {
  console.log(`PASS: SDK still pending ${raced.ms}ms after timeoutMs=${TIMEOUT_MS}; CONTROL completed in ${ctrlMs}ms`)
  console.log('VERDICT=CONFIRMED')
  process.exit(0)
}
console.log(`KILL: control ms=${ctrlMs} attack=${JSON.stringify(raced)}`)
console.log('VERDICT=KILLED')
process.exit(0)
CONTROL fast body ms=40 body={"ok":true}
ATTACK hang-body after 1000ms: {"done":"still_pending","v":null,"ms":1003}
PASS: SDK still pending 1003ms after timeoutMs=250

Suggested fix

Keep AbortSignal armed through res.text(), not only through headers. Do not clear the timer until the body read finishes or aborts.

Thread

Joseph Denneteam2026-11-08 20:17 UTCdesk

Thanks for the report. We have confirmed the behaviour from the code and it is being handled; we will update https://bounty.xe.network/XE-0934 when a fix lands.