Skip to content

Aborting HTTP2 to streaming endpoints throws an assertion error #2386

@jackschu

Description

@jackschu

Bug Description

Aborting streaming endpoints immediately the after response is ready results in an assertion failure
This might be related to #2364 but the assert is appearing in a different spot
And the repro doesnt require multiple requests to the same domain
But if these are deemed the same, happy for yall to consolidate to that one issue

Reproducible By

https://replit.com/@JS7/undici-h2-abort-failure

const undici = require('undici');

undici.setGlobalDispatcher(new undici.Agent({
  allowH2: true,
}));

(async () => {
  const controller = new AbortController();
  const response = await undici.fetch('https://mirror-cdn.xtom.com/ubuntu/dists/xenial/Release.gpg', { signal: controller.signal });
  controller.abort()
  setTimeout(()=>console.log("done"), 100);
})();

Expected Behavior

At some point I see the console.log printing "done". Nothing is thrown.

Actual Behavior

I see this and no other output

node:assert:399
    throw err;
    ^

AssertionError [ERR_ASSERTION]: The expression evaluated to a falsy value:

  assert(!this.aborted)

    at Request.onData (/home/runner/undici-h2-abort-failure/node_modules/undici/lib/core/request.js:246:5)
    at ClientHttp2Stream.<anonymous> (/home/runner/undici-h2-abort-failure/node_modules/undici/lib/client.js:1814:17)
    at ClientHttp2Stream.emit (node:events:513:28)
    at addChunk (node:internal/streams/readable:324:12)
    at readableAddChunk (node:internal/streams/readable:297:9)
    at Readable.push (node:internal/streams/readable:234:10)
    at Http2Stream.onStreamRead (node:internal/stream_base_commons:190:23) {
  generatedMessage: true,
  code: 'ERR_ASSERTION',
  actual: false,
  expected: true,
  operator: '=='
}

Environment

Node.js v18.16.1
undici@5.26.4

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