MegalaniaBlog
  1. Blog
  2. How to fix
  3. axios timeout

axios timeout: no default, ECONNABORTED, and the fix

axios waits forever unless you set timeout. What a hung server does, ECONNABORTED versus ETIMEDOUT, a retry loop, and a call that climbs. axios 1.21.

Jordan HayesDeveloper Relations
3 min read
How to fix
A request arrow leaves a terminal card and stops at a stopwatch. Behind it a server card sits with a spinning wait icon. A second arrow goes around, through a small retry loop, and reaches a page that reads 200.

The short answer: axios has timeout: 0 by default, which means no limit: in Node, a server that never answers keeps the request open. Set timeout in milliseconds, per call or with axios.create(). When it runs out, axios rejects with an AxiosError whose code is ECONNABORTED and whose message is timeout of 5000ms exceeded. Set transitional: { clarifyTimeoutError: true } to get ETIMEDOUT instead, so a timeout no longer looks like any other aborted request. There is no err.response. For retries, a small loop on that code is enough. When a page is slow because it needs a browser, post it to our API, and a call that runs out of time costs nothing.

What axios does on a slow server

Start a listener in one terminal with nc -lk 8799. It takes each connection and never answers, like a server that hangs. Run this in a second terminal:

Terminal 2
timeout 10 node -e 'require("axios").get("http://127.0.0.1:8799/")'
echo "exit code: $? (124 = still waiting when timeout stopped it after 10 s)"
node -e 'require("axios").get("http://127.0.0.1:8799/", { timeout: 5000 }).catch((e) => console.log(e.name, e.code, "|", e.message))'
Output
exit code: 124 (124 = still waiting when timeout stopped it after 10 s)
AxiosError ECONNABORTED | timeout of 5000ms exceeded
  • With the default timeout: 0, axios was still waiting after 10 seconds, when the shell stopped it.
  • With timeout: 5000, it rejected after 5 seconds: ECONNABORTED, timeout of 5000ms exceeded.
  • The limit covers the whole request, from start to the last byte, not only the wait for the first one.

How axios reports a timeout

Our test store answers fast, so give it a limit too short to meet. The error is the same one a slow site gives you:

seen.mjs
// npm install axios
import axios from "axios";

for (const transitional of [undefined, { clarifyTimeoutError: true }]) {
  try {
    await axios.get("https://lab.megalania.io/product-category/kitchen/", { timeout: 20, transitional });
  } catch (err) {
    console.log(transitional ? "clarifyTimeoutError:" : "default:", err.code, "|", err.message, "| response:", err.response);
  }
}
Output
default: ECONNABORTED | timeout of 20ms exceeded | response: undefined
clarifyTimeoutError: ETIMEDOUT | timeout of 20ms exceeded | response: undefined
  • ECONNABORTED by default, ETIMEDOUT with clarifyTimeoutError. Same message, different code, so pick one and branch on it.
  • err.response is undefined: the store never answered in 20 ms, so there is no status to read.

The free fix: timeouts and retries

Set a limit on every request, and retry a few times with a pause. This fixes servers that are slow now and then:

fix.mjs
// npm install axios
import axios from "axios";

const client = axios.create({ timeout: 20000 });

async function get(url, tries = 3) {
  for (let n = 1; ; n++) {
    try {
      return await client.get(url);
    } catch (err) {
      if (err.code !== "ECONNABORTED" || n === tries) throw err;
      console.log("try", n, "timed out, waiting", 2 * n, "s");
      await new Promise((r) => setTimeout(r, 2000 * n));
    }
  }
}

const res = await get("https://lab.megalania.io/product-category/kitchen/");
console.log(res.status, (res.data.match(/<li[^>]*class="[^"]*product type-product/g) ?? []).length, "products on the page");
Output
200 9 products on the page
  • axios.create({ timeout: 20000 }) sets the limit once for every call from that client.
  • The loop retries only ECONNABORTED, waiting 2, then 4 seconds. A 404 or a 500 fails at once, since another try would not help.
Free beta, by invite76,000 credits for 30 days, no card. Apply, and we email your invite.Apply for the beta

The fix that climbs: our API

Send the page to our API instead. We fetch it, run a real Chrome when you ask, and an answer that runs out of time costs nothing:

fetch.mjs
// npm install axios
// Run: MEG_API_KEY=YOUR_KEY node fetch.mjs https://lab.megalania.io/product-category/kitchen/
import axios from "axios";

const extra = Object.fromEntries(process.argv.slice(3).map((a) => a.split(/=(.*)/s).slice(0, 2)));
const resp = await axios.post(
  "https://get.megalania.io/v1",
  { url: process.argv[2], response_types: "markdown", ...extra },
  { headers: { Authorization: `Bearer ${process.env.MEG_API_KEY}` }, timeout: 100000, validateStatus: () => true },
);
console.log(resp.status, "| route:", resp.headers["x-route"], "| credits:", resp.headers["x-credits-charged"] ?? 0);
console.log(typeof resp.data === "string" ? resp.data.slice(0, 120) : JSON.stringify(resp.data).slice(0, 150));
Output
200 | route: http/datacenter | credits: 1
# Kitchen

Cast iron, good knives and the slow morning coffee setup.

Showing all 9 results

- ![20 cm Chef's Knife](htt
  • timeout: 100000 on the axios side is longer than our own limit of 90 seconds a page.
  • Extra key=value arguments go into the body as they are; the next run adds engine, actions and timeout.

The same call on a page whose list never finishes loading, with a 20-second limit:

Terminal
MEG_API_KEY=YOUR_KEY node fetch.mjs https://lab.megalania.io/new-arrivals/ engine=browser actions=wait_for:#item-99 timeout=20
Output
422 | route: undefined | credits: 0
{"error":{"code":"action_failed","field":"actions","message":"actions entry 0 could not run: no visible element matched its selector in time, or the t
  • Our Chrome waited for #item-99, which this 12-item list never has, until the time for actions ran out: 422 action_failed.
  • With validateStatus: () => true, axios hands you our 422 as a normal response, not an AxiosError.

One honest note: our test store is fast, so these runs show a short limit or a page that never gets ready, not a slow site. On a slow site, the call is the same; the price depends on the route that worked, and our MCP tool check_site tells you that price for free.

What it costs

What we ranRouteCredits
The kitchen category as Markdownh:dc1
A page that never got ready, in the browserc:dc0
The nc runs, seen.mjs and fix.mjs, straight from Nodenone0

Every rule is in Credits. Plans are on the pricing page.

How we measured: axios 1.21.1 on Node 24.21, one Linux server, 17 Nov 2026. nc -lk 8799 (OpenBSD netcat) as a server that never answers, and the shell's timeout to stop the call with no limit. Our test store for the short limit and for fix.mjs. Our API on our dev cluster for fetch.mjs, against the same store on our dev domain. The outputs are copied from those runs.

Limits

  • Public pages only. We do not log in, and we do not solve CAPTCHAs. When a page needs either, we stop and say so, for free.
  • A page built by JavaScript needs engine=browser. It costs more. See How to scrape JavaScript-rendered pages.
  • Slow can mean slow down. A site that answers slowly may be under load. Keep your rate low, fetch public pages only, and follow the site's terms and robots.txt.

What to do when a site answers 429 instead is in 429 Too Many Requests when scraping.