nodejs / nodejs/undici

Fetch times out without AbortController triggered

Open
#1,329 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
JavaScript
Stars
7.7k
Forks
880
Avg merge
2d 16h
Merged PRs (30d)
68

Description

Bug Description

Hello,
I'm trying to create a custom AWS lambda container runtime as a small hobby project. And since fetch is now part of the core NodeJS I wanted to give it a try. To get the lambda invocations, I need a request with a really long timeout, so I did set up an AbortController that will never be triggered:

function getNextInvocation() {
  return fetch(`http://${AWS_LAMBDA_RUNTIME_API}/2018-06-01/runtime/invocation/next`, {
    signal: new AbortController().signal,
  });
}

When I uploaded my code to aws (as a container image). And tested it, the first execution was fine, but after a few minutes I retried and got:

TypeError: fetch failed
at Object.processResponse (node:internal/deps/undici/undici:7156:34)
at Fetch.fetchFinale (node:internal/deps/undici/undici:7486:21)
at Fetch.mainFetch (node:internal/deps/undici/undici:7380:21)
at processTicksAndRejections (node:internal/process/task_queues:96:5) {
cause: HeadersTimeoutError: Headers Timeout Error
at Timeout.onParserTimeout [as _onTimeout] (node:internal/deps/undici/undici:2109:33)
at listOnTimeout (node:internal/timers:561:11)
at processTimers (node:internal/timers:502:7) {
code: 'UND_ERR_HEADERS_TIMEOUT'
}
}

Reproducible By

Full snippet of my test code:

const {
  AWS_LAMBDA_RUNTIME_API
} = process.env;

function getNextInvocation() {
  return fetch(`http://${AWS_LAMBDA_RUNTIME_API}/2018-06-01/runtime/invocation/next`, {
    signal: new AbortController().signal,
  });
}

function postResults(result, reqId) {
  return fetch(`http://${AWS_LAMBDA_RUNTIME_API}/2018-06-01/runtime/invocation/${reqId}/response`, {
    body: typeof result === 'object' ? JSON.stringify(result) : result,
    method: 'post'
  });
}

async function runIteration() {
  const invocation = await getNextInvocation();
  await postResults('OK', invocation.headers.get('Lambda-Runtime-Aws-Request-Id'));
}

async function loop() {
  while (true) {
    await runIteration();
  }
}

loop();


Expected Behavior

If the abort controller is never triggered, I'd expect to never receive a timeout error.

Logs & Screenshots

Environment

I uploaded the above code to AWS ECR and ran it in lambda as container image. My dockerfile is

FROM node:17.8-alpine

COPY *.js .

CMD ["node", "--experimental-fetch", "index.js"]
Additional context

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the fetch call in index.js and the node:17.8-alpine setup in Dockerfile, then reproduce the request using the provided AWS Lambda runtime URL. Trace the HeadersTimeoutError and verify whether an untriggered AbortController still leads to a timeout; done means the long-running fetch no longer fails unexpectedly.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, docker, javascript, node.js
Domain
api, backend, cloud
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.