undici icon indicating copy to clipboard operation
undici copied to clipboard

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

Open SukkaW opened this issue 1 year ago • 1 comments

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:

https://github.com/nodejs/undici/blob/5890e16ddd2703151ce0be0a468e13d685b89f60/lib/fetch/request.js#L838-L840

SukkaW avatar Aug 17 '22 16:08 SukkaW

@KhafraDev

ronag avatar Aug 17 '22 16:08 ronag

Thanks for reporting! Would you like to send a Pull Request to address this issue? Remember to add unit tests.

mcollina avatar Aug 17 '22 20:08 mcollina

@mcollina Actually I don't know the best way to fix it.

I could simply remove the webidl interface check to address the fix, but it might not be fetch spec compliant any more.

SukkaW avatar Aug 18 '22 05:08 SukkaW