---
id: HS0097
title: "RPC request timeouts"
url: https://carbium.sh/library/howsolana/rpc-request-timeouts
collection: How to use Solana
category: Confirmation and retries
revision: 1
updated: 2026-11-23
author: Carbium
code: MIT (LICENSE in the zip); text: all rights reserved, Carbium Corporation
---

# RPC request timeouts

One TypeScript file gives every Solana RPC read on Carbium its own abort timeout, retries a timed-out read under a single deadline, and prints how long a read took. It only reads: no keypair, no signature.

## Where a timeout lives

A web3.js `Connection` hides the HTTP request behind its methods, so a socket timeout there means swapping in your own `fetch` or waiting for the platform default. `@solana/kit` has no `Connection`. A call is a pending request, and nothing leaves the machine until you call `.send()`. `send` takes one option, an `abortSignal`, and that signal is the whole timeout mechanism: when it fires, the request is cancelled and the promise rejects.

Node ships the signal you need. `AbortSignal.timeout(ms)` fires after `ms` milliseconds, and its `aborted` flag tells you afterwards that the timer ended the call. The file below gives every read a fresh signal, because a signal fires once and cannot be reused for a second try.

The file builds one transport from the endpoint and key in the environment and reuses it for every read, so the connection setup is paid once.

## The code

Install `@solana/kit` at 8.6.0, export `CARBIUM_KEY` and run the file with Node 24, which strips the types on load. It takes no arguments.

`main.ts` (run: `node main.ts`)

```ts
// HS0097 · RPC request timeouts
// https://carbium.sh/library/howsolana/rpc-request-timeouts
// Copyright (c) Carbium Corporation. MIT License (LICENSE). Keep this notice.
// SPDX-License-Identifier: MIT

import { setTimeout as sleep } from "node:timers/promises";
import { createDefaultRpcTransport, createSolanaRpcFromTransport } from "@solana/kit";

const key = process.env.CARBIUM_KEY;
if (!key) {
  console.error("Set CARBIUM_KEY to your Carbium API key.");
  process.exit(1);
}
const url = process.env.CARBIUM_RPC_URL ?? "https://services.carbium.sh";
const rpc = createSolanaRpcFromTransport(createDefaultRpcTransport({ url, headers: { "x-api-key": key } }));

type Pending<T> = { send(options?: { abortSignal?: AbortSignal }): Promise<T> };

// One read with its own timer. The signal fires once, so every try gets a new one.
async function readWithDeadline<T>(make: () => Pending<T>, perTryMs: number, totalMs: number): Promise<{ value: T; tries: number }> {
  const end = Date.now() + totalMs;
  for (let tries = 1; ; tries++) {
    const left = end - Date.now();
    if (left <= 0) throw new Error(`deadline of ${totalMs} ms passed after ${tries - 1} tries`);
    const signal = AbortSignal.timeout(Math.min(perTryMs, left));
    try {
      return { value: await make().send({ abortSignal: signal }), tries };
    } catch (e) {
      if (!signal.aborted) throw e; // an HTTP or JSON-RPC error goes to the caller, which knows its cause
      console.log(`try ${tries} timed out after ${Math.min(perTryMs, left)} ms`);
      await sleep(Math.min(200 * 2 ** (tries - 1), Math.max(0, end - Date.now())));
    }
  }
}

// 1. A 1 ms budget cannot be met, so this read always shows what a timeout looks like.
const short = AbortSignal.timeout(1);
try {
  await rpc.getSlot({ commitment: "confirmed" }).send({ abortSignal: short });
  console.log("forced timeout: the read answered inside 1 ms");
} catch (e) {
  console.log(`forced timeout: ${(e as Error).name}, signal aborted: ${short.aborted}`);
}

// 2 and 3. Two reads side by side, each with its own per-try limit under an 8 s deadline.
const results = await Promise.allSettled([
  readWithDeadline(() => rpc.getSlot({ commitment: "confirmed" }), 4000, 8000),
  (async () => {
    const start = performance.now();
    const { value } = await readWithDeadline(() => rpc.getLatestBlockhash({ commitment: "confirmed" }), 5000, 8000);
    return { value, ms: Math.round(performance.now() - start) };
  })(),
]);

const [slot, blockhash] = results;
if (slot.status === "fulfilled") console.log(`slot: ${slot.value.value} after ${slot.value.tries} try`);
else console.log("slot failed:", (slot.reason as Error).message);
if (blockhash.status === "fulfilled") {
  console.log(`blockhash: ${blockhash.value.value.value.blockhash} in ${blockhash.value.ms} ms`);
} else console.log("blockhash failed:", (blockhash.reason as Error).message);
```

The first read gets a 1 ms budget on purpose. No network round trip finishes that fast, so it always times out, and you see what a timeout looks like before you need to handle a real one. The second and third run side by side through `readWithDeadline`. The slot read gives each try 4 seconds and the whole job 8. The blockhash read gives each try 5 seconds under the same 8 second deadline and prints its elapsed time.

`readWithDeadline` takes a function that builds the request, not the request itself. Each try builds a new pending request and a new signal. Only a timeout is retried. Any other error, such as an HTTP 429 or a JSON-RPC error, is thrown at once to the caller, which knows whether a second try can help and, for a 429, how long to wait.

## Reading the output

| Line | What it shows |
|---|---|
| forced timeout | The 1 ms read was cancelled by its own signal. The line names the error and confirms the signal had fired. |
| slot | The result of the retried read, plus the number of tries it took. One try is the normal case. |
| blockhash | The blockhash read with its elapsed time in milliseconds, measured around the call on your machine. |
| failed | Any read that threw something other than the planned timeout, with its message. |

The elapsed time includes DNS, TLS setup on the first call, any rate-limit wait and the reply. A first call on a fresh process is slower than the next ones, because the connection is new. Pick a timeout from what you measure on your own host and region over many calls, never from one run.

> A timeout is a client-side decision. The server may have received the request and answered it after you gave up. For a read that costs nothing but a repeat. For anything that writes, a cancelled call tells you nothing about whether it landed, so check by signature before you send again.

## Choosing the numbers

Two limits do different jobs. The per-try limit protects you from one stuck connection: it should sit well above the normal reply time and above any rate-limit wait the server adds. The total deadline protects the caller, such as a web request or a queue job, from a read that keeps retrying past the point where its answer is useful.

- Set the per-try limit above 3 seconds. A call over its rate waits once and is served if its cells refill within 1 s, and a call with no free validator permit waits up to 3 s, so a shorter limit cancels calls that would have been answered.
- Make the total deadline a multiple of the per-try limit. Two or three tries fit most jobs.
- Back off between tries. The file waits 200 ms, then 400 ms, and never longer than the time left.
- Give heavier reads more room. A `getTransaction` call costs 50 cells and a `getSlot` call costs 1, and the larger reply takes longer to send.

An abort needs a single pass through the event loop to take effect, so a timeout of 2000 ms can surface a few milliseconds late.

## On Carbium

`getSlot` and `getHealth` are cheap cached reads at 1 cell each, so a retry on them barely touches your [rate limits](https://carbium.sh/docs/rpc). They run at 5 requests per second on Free, 30 on Dev, 100 on Business and 500 on Pro. Those limits belong to the account, so every key you own draws on one budget, and a retry loop in one service shrinks what another has left.

A call that goes over its rate does not time out. It either waits once and succeeds, or it gets HTTP 429 with a retry-after hint. That is a reply your code can read: wait for the hinted seconds, on a branch of its own apart from the timeout branch. [Webhook-to-RPC fetch retries](https://carbium.sh/library/howsolana/webhook-to-rpc-fetch-retries) shows the retry side of that branch for reads that follow a webhook.

Connections stay open for 600 s and TLS sessions resume, so a single client reused across calls pays the connection setup once. Creating a new transport per call makes every read look slower than it is, and a timeout tuned against that setup cost ends up too loose once you reuse the client.

A subscription on `wss://services.carbium.sh` is one long-lived connection. Its abort signal only ends it, and silence on it can mean a quiet chain or a dead socket. [Subscription dead-man alert](https://carbium.sh/library/integrate/subscription-dead-man-alert) covers that case with a watchdog.

## Where it ends

A timeout tells you that no answer arrived in time. It cannot tell you why: a slow network path, a stalled connection and a busy server all look the same from the client. Add the HTTP status and the error code to your logs, and a repeat of timeouts on one host becomes something you can trace.

The retry loop here suits reads. A cancelled write needs its own check before it is sent again, and a retry that blindly resends can pay a fee twice or act twice.

Abort signals cancel the request on your side only. A read you abandoned and then retried can be served twice.

The numbers in the file, 4 seconds a try and 8 for the job, are starting points for a read of a few hundred bytes. A large `getBlock` or a long run of signatures needs measured values of its own.

## When it goes wrong

| What goes wrong | What to do |
|---|---|
| The file exits with `Set CARBIUM_KEY to your Carbium API key.` | Export the key in the shell that runs the file, for example `export CARBIUM_KEY=...`. The file reads it from the environment so it never sits in source or in a log. |
| Every call times out, even with a generous limit. | The URL is probably wrong or unreachable from your network. Check `CARBIUM_RPC_URL` if you set it, and leave it unset to use `https://services.carbium.sh`. A firewall that drops packets gives you a timeout with no error reply. |
| Calls time out only under load, and the retries make it worse. | A call can wait up to 3 s for a free validator permit, so a per-try limit under that cancels it and the retry adds another call to the budget. Raise the per-try limit above 3 s, cap the number of tries, and check the account's [rate limits](https://carbium.sh/docs/limits), which every key of the account shares. |
| A call is cancelled and the reply shows up in the server's records anyway. | This is how a client-side abort works. The server may finish a request you abandoned. Keep the retried calls to reads, and check a write by its signature before you send it again. |
| HTTP 429 with a retry-after hint appears where you expected a timeout. | The call went over its rate and the server answered with a 429. Wait for the hinted seconds and try once more instead of treating it as a stuck connection. If it repeats, slow the loop or move to a plan with a higher rate. |

## Questions

### Can I set one timeout for the whole client, as a web3.js Connection option would?

The kit transport has no global timeout, so each `send` gets its own signal. A small wrapper such as `readWithDeadline` gives you the same effect in one place, and it lets you pick a different limit for a heavy read.

### Why a new AbortSignal on every try?

A signal fires once and stays fired. If you reuse it, the second try is cancelled the moment it starts. `AbortSignal.timeout` builds a fresh one for each try.

### How do I tell a timeout from a network error?

Check the signal you passed. If its `aborted` flag is set, your timer ended the call. Any other rejection came from the transport or the server, and retrying it is a decision for the code that knows the cause.

### What timeout should I use for a read?

Start above 3 seconds, since a call can wait up to 3 s for a free validator permit and still be served, then adjust from what you measure across many calls. Give heavy reads such as `getTransaction` more room than a `getSlot` call.

## Related

- [Webhook-to-RPC fetch retries](https://carbium.sh/library/howsolana/webhook-to-rpc-fetch-retries) (How to use Solana, HS0041)
- [Subscription dead-man alert](https://carbium.sh/library/integrate/subscription-dead-man-alert) (Integrations, I0068)
- [carbium.sh/docs/rpc](https://carbium.sh/docs/rpc)
- [carbium.sh/docs/limits](https://carbium.sh/docs/limits)
- [carbium.sh/docs/endpoints](https://carbium.sh/docs/endpoints)
- [carbium.sh/docs/errors](https://carbium.sh/docs/errors)
