AbortError

Node.js ErrorRuntime ErrorMediumLast updated: May 12, 2024Tested on:Node.js v20 LTSNPM v10.2June 2026

AbortError is thrown when an asynchronous operation is intentionally cancelled before it completes.

AbortError Quick Fix⏱️ Est. Fix Time: 3 minutes

Usually happens because:

  • Request Timeout
  • User Cancellation
  • Multiple Search Requests

🔍 Quick Checklist:

What is AbortError?

AbortError is thrown when an asynchronous operation is intentionally cancelled before it completes. Unlike most runtime errors, an AbortError usually doesn't indicate that something is broken. It simply means that an operation was stopped because the application, user, or another part of the system requested cancellation. You'll most commonly encounter AbortError when working with fetch(), AbortController, streams, timers, file operations, and network requests. If you've added request timeouts or cancellation logic to your application, seeing an AbortError is often expected behavior. Imagine your application starts downloading a large file. Halfway through the download, the user closes the page. Continuing the download would waste bandwidth and system resources, so your application cancels the request. Instead of completing successfully, the operation throws an AbortError. In other words: The operation didn't fail because of invalid code or a server problem—it stopped because cancellation was requested.

Common Causes

  • Request Timeout: Developers often create an AbortController to stop requests that take too long.
  • User Cancellation: A user clicks 'Cancel Upload' or navigates away from the page, prompting the application to abort the request intentionally.
  • Multiple Search Requests: Instead of waiting for every keypress request to finish, the application cancels older queries to only allow the latest to complete, improving responsiveness.
  • Stream Cancellation: Readable streams are aborted if the stream closes before reading is complete, throwing an AbortError.
CauseFrequency
Request Timeout⭐⭐⭐⭐⭐
User Cancellation⭐⭐⭐⭐
Multiple Search Requests⭐⭐⭐

Common Mistakes

  • Treating AbortError like every other error: Many applications log it as a critical exception, which creates unnecessary noise in logs.
  • Ignoring AbortError completely: While expected cancellations can be ignored, unexpected ones may indicate that your cancellation logic is firing too early.
  • Reusing AbortController instances: An AbortController cannot be 'reset'. Once abort() has been called, its signal remains aborted. Create a new controller for each new operation.

How to Fix

1If cancellation is expected: Don't treat it as an application error. Instead, handle it gracefully by checking if error.name === 'AbortError' and returning quietly.
2If requests are timing out: Increase the timeout limit only if the operation genuinely requires more time. Avoid setting extremely long timeouts without clear reasons.
3If the AbortController fires too early: Review where abort() is being called. A common mistake is accidentally reusing the same controller across multiple requests.
4If users frequently cancel operations: This isn't necessarily a bug. Handle the cancellation gracefully and update the UI accordingly to reflect the user's action.

Framework-Specific Examples

If the request takes longer than three seconds, the controller aborts it, the promise rejects with AbortError, and the code handles it without crashing the application.

Complete Example Example
const controller = new AbortController();

setTimeout(() => controller.abort(), 3000);

async function loadUser() {
    try {
        const response = await fetch(
            "https://jsonplaceholder.typicode.com/users/1",
            {
                signal: controller.signal
            }
        );

        const data = await response.json();
        console.log(data);

    } catch (error) {
        if (error.name === "AbortError") {
            console.log("Request cancelled.");
            return;
        }
        console.error(error);
    }
}

loadUser();

Server Configuration Examples

Enabling client abort detection on Nginx proxy layers.

Nginx Proxy Configuration Config
proxy_ignore_client_abort off;

Best Practices

  • Create a new AbortController instance for each independent request.
  • Catch and evaluate AbortError separately from other exceptions.
  • Avoid reporting expected cancellations to error monitoring services (e.g. Sentry).
  • Use cancellation to improve user experience, not to hide server performance problems.
  • Display appropriate UI feedback when an operation is cancelled.

Frequently Asked Questions (FAQ)

Q: Is AbortError a bug?

Not necessarily. Most of the time it simply indicates that an operation was intentionally cancelled.

Q: Can I ignore AbortError?

Yes, if the cancellation was expected and your application handles it correctly. Unexpected AbortError instances should still be investigated.

Q: Is AbortError specific to Node.js?

No. It also appears in browser APIs that support AbortController, including the Fetch API and streams.

Q: What is the difference between AbortError and TimeoutError?

TimeoutError is thrown when a network socket exceeds inactivity bounds. AbortError is a cancellation signal triggered programmatically by AbortController, even if triggered by a timeout timer.

Still having this problem?

Didn't solve your problem?

SuggestRequest Error