Skip to content

Can't bring custom abort-controller implementation to undici.fetch #1605

@SukkaW

Description

@SukkaW

Bug Description

We are using abort-controller from npm in our codebase with undici. undici fails with:

TypeError: AbortSignal: Expected [object AbortSignal] to be an instance of AbortSignal.

Reproducible By

https://replit.com/@SukkaW/ImaginaryDishonestCommunication#index.js

const { AbortController } = require('abort-controller');
const { fetch } = require('undici');

const controller = new AbortController()
controller.abort()

try {
  fetch('https://example.com', {
    signal: controller.signal,
  })
} catch (error) {
  console.log(error.message)
}

Expected Behavior

The error AbortError: The operation is aborted should be shown instead.

Environment

Node.js 18.7.0 on macOS 13 Beta 4

Additional Context

I have searched the codebase of undici and I notice this:

undici/lib/fetch/request.js

Lines 838 to 840 in 5890e16

webidl.converters.AbortSignal = webidl.interfaceConverter(
AbortSignal
)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingfetch

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions