Skip to content
New issue

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

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

Already on GitHub? # to your account

Z_DATA_ERROR when fetching a "Content-Encoding: gzip, deflate" response from the server #3762

Closed
kettanaito opened this issue Oct 23, 2024 · 5 comments
Labels
bug Something isn't working

Comments

@kettanaito
Copy link
Contributor

kettanaito commented Oct 23, 2024

Bug Description

fetch is terminated with a Z_DATA_ERROR when fetching a gzip, deflate compressed response from the server.

Reproducible By

Here's a 0 dependency reproduction:

  1. https://github.com/kettanaito/undici-gzip-deflate
  2. node ./index.js

Here's a copy-pastable reproduction:

import http from 'node:http'
import zlib from 'node:zlib'

const server = new http.Server((req, res) => {
  res.setHeader('content-encoding', 'gzip, deflate')
  res.end(zlib.deflateSync(zlib.gzipSync('hello world')))
})

server.listen(56789, async () => {
  const response = await fetch('http://localhost:56789/', {
    headers: { 'accept-encoding': 'gzip, deflate' },
  })
  const text = await response.text()
  console.assert(text === 'hello world')
})

Expected Behavior

  1. Fetch happens without errors.
  2. await response.text() returns a decompressed response string 'hello world'.

Logs & Screenshots

node:internal/deps/undici/undici:11190
            fetchParams.controller.controller.error(new TypeError("terminated", {
                                                    ^

TypeError: terminated
    at Fetch.onAborted (node:internal/deps/undici/undici:11190:53)
    at Fetch.emit (node:events:517:28)
    at Fetch.terminate (node:internal/deps/undici/undici:10375:14)
    at fetchParams.controller.resume (node:internal/deps/undici/undici:11167:36)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  [cause]: Error: incorrect header check
      at Zlib.zlibOnError [as onerror] (node:zlib:189:17) {
    errno: -3,
    code: 'Z_DATA_ERROR'
  }
}

Node.js v18.20.3

Environment

Reproducible on all versions of Node:

  • 18.20.3
  • 20.11.0
  • 22.3.0
  • 23.0.0
@Uzlopak
Copy link
Contributor

Uzlopak commented Oct 23, 2024

isnt this alread fixed in #3632 ?

@kettanaito
Copy link
Contributor Author

kettanaito commented Oct 23, 2024

@Uzlopak, still reproducible on v23.0.0. Do you have an exact Node.js version where that fix has been merged?

I can see that backporting to v6 failed. Can it be that the fix was never backported?

@Uzlopak
Copy link
Contributor

Uzlopak commented Oct 23, 2024

I backported it manually. #3700

Use undici 6.20.0 directly to test it.

@tsctx
Copy link
Member

tsctx commented Oct 23, 2024

Sorry, I forgot to backport #3343 to 6.x, this should fix it.

@tsctx
Copy link
Member

tsctx commented Oct 23, 2024

Fixed by #3764

@tsctx tsctx closed this as completed Oct 23, 2024
gauthier-th added a commit to Fallenbagel/jellyseerr that referenced this issue Dec 3, 2024
This fixes an issue with the Fetch API that is unable to decode the response from Emby during setup.
Related to nodejs/undici#3762
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants