upstash/context7 · warning · Context7Error

timedOut ? "request_timeout" : "request_aborted"

timedOut ? "request_timeout" : "request_aborted"

Error message

timedOut ? "Request timed out" : "Request was aborted"

What it means

Context7Error (code "request_timeout" or "request_aborted") thrown by request when the abort signal is already aborted before/at the start of the fetch — i.e. the request timed out per the configured timeout, or the caller aborted via an external AbortSignal, before the request could run.

Source

Thrown at packages/sdk/src/http/index.ts:85

  public async request<TResult>(request: Context7Request): Promise<Context7Response<TResult>> {
    const method = request.method ?? "POST";
    const abortState = createAbortState(
      [resolveSignal(this.options.signal), request.signal],
      request.timeout ?? this.options.timeout
    );
    const init: RequestInit = {
      cache: normalizeCache(request.cache ?? this.options.cache),
      method,
      headers: this.headers,
      body: request.body === undefined ? undefined : JSON.stringify(request.body),
      keepalive: this.options.keepAlive,
      signal: abortState.signal,
    };

    try {
      if (abortState.signal?.aborted) {
        throw abortError(abortState.signal.reason, abortState.timedOut());
      }

      const { response, metadata } = await this.fetchWithRetry(
        buildUrl(this.baseUrl, method, request),
        init,
        method,
        abortState
      );
      if (!response.ok) {
        await throwResponseError(
          response,
          metadata,
          isTransientStatus(response.status) || this.retry.statuses.has(response.status)
        );
      }
      return await parseSuccessResponse<TResult>(response, metadata);
    } catch (error) {
      if (abortState.signal?.aborted && !isContext7AbortError(error)) {

View on GitHub (pinned to 80e681a507)

Solutions

  1. Create a fresh AbortSignal per request (AbortSignal.timeout(ms) or new AbortController().signal) instead of reusing an already-aborted one.
  2. Increase the client timeout option (timeout in ms) or set timeout: false if the operation legitimately takes longer.
  3. Check upstream caller code that aborts the shared controller and only abort after the request completes.
  4. Catch the error and check code === 'request_timeout' vs 'request_aborted' to distinguish timeout from deliberate cancellation.

Example fix

// before
const signal = AbortSignal.timeout(1000);
await slowWork(); // >1s
await client.exec(cmd, { signal }); // aborted before start
// after
const signal = AbortSignal.timeout(10000); // fresh, adequately sized
await client.exec(cmd, { signal });
Defensive patterns

Strategy: try-catch

Validate before calling

const signal = mySignal;
if (signal?.aborted) throw new Error('Refusing to call: signal already aborted');

Type guard

function isAbortFailure(e: unknown): e is Context7Error {
  return e instanceof Context7Error && (e.code === 'request_timeout' || e.code === 'request_aborted');
}

Try / catch

try {
  return await client.exec(cmd, { signal });
} catch (e) {
  if (isAbortFailure(e)) {
    if (e.code === 'request_aborted') return undefined; // deliberate cancel
    return await client.exec(cmd); // timeout: retry with fresh default timeout
  }
  throw e;
}

Prevention

When it happens

Trigger: Passing a signal option that is already aborted, using an AbortSignal.timeout(ms) that fired before the call, or a client-level timeout that elapsed between requests so abortState.signal.reason triggers abortError at request entry.

Common situations: Reusing a timed-out AbortSignal.timeout token, a shared cancellation controller aborted by another request, or very small timeout values in slow environments.

Understand the failure class

Background: Request timed out: what client-side request timeouts mean across libraries (Request timed out, TIMED_OUT, APITimeoutError) — this error's family across 39 libraries.

Related errors


AI-assisted analysis of upstash/context7@80e681a507 (2026-09-08). Data as JSON: /api/errors/475b734318277790. Report an issue: GitHub.