Skip to content

Options freezing breaks abort signal #2099

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
svvac opened this issue Aug 4, 2022 · 1 comment · Fixed by #2100
Closed

Options freezing breaks abort signal #2099

svvac opened this issue Aug 4, 2022 · 1 comment · Fixed by #2100

Comments

@svvac
Copy link
Contributor

svvac commented Aug 4, 2022

The Options objects freeze the abort signal if it gets passed. As a result setting the signal prop ends up breaking the signal under node as the builtin code sets private properties when calling AbortController.abort().

This makes it impossible to pass a default abort signal to a Got instance as the runtime will throw when aborting.

  • NodeJS v16.15.1
  • Got v12.3.0
import got from 'got';
const abortCtrl = new AbortController();
const got2 = got.extend({
    signal: abortCtrl.signal,
});
abortCtrl.abort();
$ node test.mjs
node:internal/abort_controller:279
  signal[kAborted] = true;
                   ^

TypeError: Cannot assign to read only property 'Symbol(kAborted)' of object '#<AbortSignal>'
    at abortSignal (node:internal/abort_controller:279:20)
    at AbortController.abort (node:internal/abort_controller:315:5)
    at file:///tmp/test.mjs:6:11
    at ModuleJob.run (node:internal/modules/esm/module_job:198:25)
    at async Promise.all (index 0)
    at async ESMLoader.import (node:internal/modules/esm/loader:385:24)
    at async loadESM (node:internal/process/esm_loader:88:5)
    at async handleMainPromise (node:internal/modules/run_main:61:12)
@svvac
Copy link
Contributor Author

svvac commented Aug 4, 2022

Note that it can even break when not calling AbortController.abort(), for example when the signal gets many listeners added because of the warning emitted by node.

import got from 'got';
const abortCtrl = new AbortController();
const got2 = got.extend({
    signal: abortCtrl.signal,
});

for (let i = 0; i < 50; i++) {
    abortCtrl.signal.addEventListener('abort', () => { /* noop */ });
}
$ node test2.mjs
node:internal/event_target:423
      this[kMaxEventTargetListenersWarned] = true;
                                           ^

TypeError: Cannot assign to read only property 'Symbol(events.maxEventTargetListenersWarned)' of object '#<AbortSignal>'
    at AbortSignal.[kNewListener] (node:internal/event_target:423:44)
    at AbortSignal.[kNewListener] (node:internal/abort_controller:173:24)
    at AbortSignal.addEventListener (node:internal/event_target:535:23)
    at file:///tmp/test2.mjs:8:22
    at ModuleJob.run (node:internal/modules/esm/module_job:198:25)
    at async Promise.all (index 0)
    at async ESMLoader.import (node:internal/modules/esm/loader:385:24)
    at async loadESM (node:internal/process/esm_loader:88:5)
    at async handleMainPromise (node:internal/modules/run_main:61:12)

I suspect there might be other cases as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant