Skip to content

RetryAgent doesn't keep the event loop alive #3975

@blinsay

Description

@blinsay

Bug Description

When using RetryAgent, Node exits while there are pending retries in flight.

Reproducible By

I've been playing around in a brand new node project with only unidici installed and trying to run the following script. This is mostly copy/pasted from the docs - I don't think I'm doing anything unorthodox here.

import { request, Agent, RetryAgent } from "undici";

const resp = await request("http://httpbin.org/status/418", {
  dispatcher: new RetryAgent(new Agent(), {
    statusCodes: [418],
  }),
  headers: { "User-Agent": "teapot" },
});

console.log("status:", resp.statusCode);
console.log("headers:", resp.headers);

Expected Behavior

I'd expect to get either an HTTP response or a retry error.

Logs & Screenshots

$ node example.js; echo "exit code: $status"
Warning: Detected unsettled top-level await at file:///[redacted]/example.js:3
const resp = await request("http://httpbin.org/status/418", {
             ^



exit code: 13

Additional context

$ node --version
v23.5.0
$ grep undici package.json
    "undici": "^7.2.0"

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions