Skip to content

bug(sdk): request retry throws on abort during backoff — violates the never-throws Result contract #399

Description

@taitelee

Summary

When a request is aborted while the SDK is sleeping between retries after a network error, sleep rejects with an AbortError inside the catch block where nothing catches it, so request() (and insert()/fetch()/…) rejects instead of returning { ok: false, error: { code: "ABORTED" } }.

Detail

clients/ts/src/http.ts:102-105:

lastError = networkError(e);
if (attempt < maxAttempts - 1) {
  await sleep(backoff(attempt), opts.signal);  // rejects on abort, uncaught
}

The 5xx / Retry-After sleeps (:78, :86) are inside the try, so an abort there is caught and mapped to the ABORTED Result; the network-error backoff sleep is in the catch, so its rejection escapes. The documented contract (types.ts:13-18) is that request never throws.

Fix direction

Wrap the catch-block sleep in its own try/catch (or check the signal) and return the ABORTED Result, matching the other two sleep sites.

Found in a repo-wide audit; verified by code trace. #198/#201 are about error types, not this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/sdkTypeScript SDK (clients/ts/)bugSomething isn't working

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    Status
    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions