How It Works Features Pricing Blog Error Guides
Log In Start Free Trial
Next.js · TypeScript/React

Fix TimeoutError: API resolved without sending a response for /api/users, this may result in stalled requests in Next.js

This warning appears when a Next.js API route finishes execution without calling res.status().json() or res.end(). This typically happens when an async operation completes but the response is never sent, or when early returns skip the response. Fix it by ensuring every code path sends a response.

Reading the Stack Trace

warn - API resolved without sending a response for /api/users, this may result in stalled requests. at apiResolver (/app/node_modules/next/dist/server/api-utils/node.js:372:15) at processTicksAndRejections (node:internal/process/task_queues:95:5) at async DevServer.runApi (/app/node_modules/next/dist/server/next-server.js:487:9) at async Object.fn (/app/node_modules/next/dist/server/next-server.js:735:37) at async Router.execute (/app/node_modules/next/dist/server/router.js:247:36) at async DevServer.run (/app/node_modules/next/dist/server/base-server.js:347:29) at async DevServer.handleRequest (/app/node_modules/next/dist/server/base-server.js:285:20)

Here's what each line means:

Common Causes

1. Missing response in async handler

The handler awaits an async operation but forgets to send the response afterward, causing the request to hang.

export default async function handler(req, res) {
  const users = await db.query('SELECT * FROM users');
  // Forgot to send the response
}

2. Conditional response with missing branch

Only some branches of the conditional logic send a response, leaving other paths without one.

export default async function handler(req, res) {
  if (req.method === 'POST') {
    const user = await createUser(req.body);
    return res.status(201).json(user);
  }
  // GET and other methods never send a response
}

3. Error swallowed in try-catch

An error is caught but the catch block does not send an error response, leaving the request hanging.

export default async function handler(req, res) {
  try {
    const data = await fetchData();
    res.status(200).json(data);
  } catch (error) {
    console.error(error);
    // No response sent in catch block
  }
}

The Fix

Ensure every possible code path sends a response. Add explicit handlers for each HTTP method and a fallback 405 response for unsupported methods so no request is left without a response.

Before (broken)
export default async function handler(req, res) {
  if (req.method === 'POST') {
    const user = await createUser(req.body);
    return res.status(201).json(user);
  }
  // GET never sends a response
}
After (fixed)
export default async function handler(req, res) {
  if (req.method === 'POST') {
    const user = await createUser(req.body);
    return res.status(201).json(user);
  }

  if (req.method === 'GET') {
    const users = await getUsers();
    return res.status(200).json(users);
  }

  return res.status(405).json({ error: 'Method not allowed' });
}

Testing the Fix

import { createMocks } from 'node-mocks-http';
import handler from '@/pages/api/users';

describe('/api/users', () => {
  it('returns 200 and users for GET', async () => {
    const { req, res } = createMocks({ method: 'GET' });
    await handler(req, res);
    expect(res._getStatusCode()).toBe(200);
    expect(JSON.parse(res._getData())).toBeInstanceOf(Array);
  });

  it('returns 201 and created user for POST', async () => {
    const { req, res } = createMocks({ method: 'POST', body: { name: 'Alice' } });
    await handler(req, res);
    expect(res._getStatusCode()).toBe(201);
  });

  it('returns 405 for unsupported methods', async () => {
    const { req, res } = createMocks({ method: 'DELETE' });
    await handler(req, res);
    expect(res._getStatusCode()).toBe(405);
  });
});

Run your tests:

npm test

Pushing Through CI/CD

git checkout -b fix/api-route-missing-response,git add src/pages/api/users.ts src/pages/api/__tests__/users.test.ts,git commit -m "fix: ensure all API route code paths send a response",git push origin fix/api-route-missing-response

Your CI config should look something like this:

name: CI
on:
  pull_request:
    branches: [main]
jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: '20'
          cache: 'npm'
      - run: npm ci
      - run: npm test -- --coverage
      - run: npm run build

The Full Manual Process: 18 Steps

Here's every step you just went through to fix this one bug:

  1. Notice the error alert or see it in your monitoring tool
  2. Open the error dashboard and read the stack trace
  3. Identify the file and line number from the stack trace
  4. Open your IDE and navigate to the file
  5. Read the surrounding code to understand context
  6. Reproduce the error locally
  7. Identify the root cause
  8. Write the fix
  9. Run the test suite locally
  10. Fix any failing tests
  11. Write new tests covering the edge case
  12. Run the full test suite again
  13. Create a new git branch
  14. Commit and push your changes
  15. Open a pull request
  16. Wait for code review
  17. Merge and deploy to production
  18. Monitor production to confirm the error is resolved

Total time: 30-60 minutes. For one bug.

Or Let bugstack Fix It in Under 2 minutes

Every step above? bugstack does it automatically.

Step 1: Install the SDK

npm install bugstack-sdk

Step 2: Initialize

import { initBugStack } from 'bugstack-sdk'

initBugStack({ apiKey: process.env.BUGSTACK_API_KEY })

Step 3: There is no step 3.

bugstack handles everything from here:

  1. Captures the stack trace and request context
  2. Pulls the relevant source files from your GitHub repo
  3. Analyzes the error and understands the code context
  4. Generates a minimal, verified fix
  5. Runs your existing test suite
  6. Pushes through your CI/CD pipeline
  7. Deploys to production (or opens a PR for review)

Time from error to fix deployed: Under 2 minutes.

Human involvement: zero.

Try bugstack Free →

No credit card. 5-minute setup. Cancel anytime.

Deploying the Fix (Manual Path)

  1. Run the test suite locally to confirm all API methods respond correctly.
  2. Open a pull request with the API route fix.
  3. Wait for CI checks to pass on the PR.
  4. Have a teammate review and approve the PR.
  5. Merge to main and verify the API routes work in staging.

Frequently Asked Questions

BugStack tests every code path in the API route handler, verifies each returns a proper response, and confirms the build completes before marking the fix safe.

Every fix is delivered as a pull request with full CI validation. Your team reviews and approves before anything reaches production.

Yes. Stalled requests consume server connections and can exhaust the connection pool, eventually causing the entire application to become unresponsive.

Yes. On Vercel or AWS Lambda, a stalled request will hit the function timeout limit (default 10s on Vercel), resulting in a 504 Gateway Timeout error for the client.