Skip to content
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

Client.close() does not wait for requests to finish in HTTP2 mode #3671

Open
matthieusieben opened this issue Oct 3, 2024 · 1 comment
Open
Assignees
Labels
bug Something isn't working H2 Pull requests or issues related to HTTP/2

Comments

@matthieusieben
Copy link
Contributor

matthieusieben commented Oct 3, 2024

Bug Description

Dispatcher.close() is documented as:

Closes the client and gracefully waits for enqueued requests to complete before invoking the callback (or returning a promise if no callback is provided).

However, when using HTTP2 mode, the requests are terminated before the pending requests complete.

Reproducible By

import { Client } from 'undici'

const url = new URL('https://identity.foundation/.well-known/did.json')

const dispatcher = new Client(url.origin, {
  allowH2: true, // <=== "true" here causes an error. "false" doesn't
})

const res = await globalThis.fetch(url, { dispatcher })

dispatcher.close().then(
  () => {
    console.info('closed')
  },
  (err) => {
    console.error('failed closing', err)
  },
)

await res.json()
/**
 * TypeError: terminated
 *       at Request.onError (node_modules/.pnpm/undici@6.19.8/node_modules/undici/lib/core/request.js:299:27)
 *       at Object.errorRequest (node_modules/.pnpm/undici@6.19.8/node_modules/undici/lib/core/util.js:638:13)
 *       at abort (node_modules/.pnpm/undici@6.19.8/node_modules/undici/lib/dispatcher/client-h2.js:277:10)
 *       at ClientHttp2Stream.<anonymous> (node_modules/.pnpm/undici@6.19.8/node_modules/undici/lib/dispatcher/client-h2.js:452:5)
 */

Expected Behavior

Same behavior as when allowH2: false: no error & client can be closed before completing.

Logs & Screenshots

Environment

Node: v18.20.4
Undici: 6.19.8

@metcoder95
Copy link
Member

The issue roots to the fact that H2 is half connected to the queueing system of undici. Working on connecting the H2 part now.

@metcoder95 metcoder95 self-assigned this Oct 4, 2024
@metcoder95 metcoder95 added the H2 Pull requests or issues related to HTTP/2 label Oct 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working H2 Pull requests or issues related to HTTP/2
Projects
None yet
Development

No branches or pull requests

2 participants