Skip to content

abortcontroller & request.clone issue with fetch #2227

@KhafraDev

Description

@KhafraDev
  import { Request } from 'undici'
  import { ok, strictEqual } from 'node:assert'

  const controller = new AbortController();
  const signal = controller.signal;

  const request = new Request('http://a', { signal });
  const clonedRequest = request.clone();

  const log = [];

  request.signal.addEventListener('abort', () => log.push('original-aborted'));
  clonedRequest.signal.addEventListener('abort', () => log.push('clone-aborted'));

  controller.abort();

  strictEqual(log, ['original-aborted', 'clone-aborted'], "Abort events fired in correct order");
  ok(request.signal.aborted, 'Signal aborted');
  ok(clonedRequest.signal.aborted, 'Signal aborted');

cc @atlowChemi since you recently made a PR regarding abortcontroller, hopefully you can help. I don't know enough about EventTarget and order of events to fix this

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