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

AxiosError: unexpected end of file #5346

Closed
atulmy opened this issue Dec 6, 2022 · 36 comments · Fixed by #5353
Closed

AxiosError: unexpected end of file #5346

atulmy opened this issue Dec 6, 2022 · 36 comments · Fixed by #5353

Comments

@atulmy
Copy link

atulmy commented Dec 6, 2022

Describe the bug

AxiosError: unexpected end of file

Was not present before 1.2.1

To Reproduce

No response

Code snippet

No response

Expected behavior

No response

Axios Version

1.2.1

Adapter Version

No response

Browser

No response

Browser Version

No response

Node.js Version

No response

OS

No response

Additional Library Versions

No response

Additional context/Screenshots

No response

@atulmy
Copy link
Author

atulmy commented Dec 6, 2022

Z_BUF_ERROR

@Flupster
Copy link

Flupster commented Dec 7, 2022

I've been having a similar issue downgrading to axios v1.2.0 will fix the problem

Something is broken with Brotli decompression and I think the culprit is somewhere in this merge #5306

An alternative if you don't want to downgrade right now is to force an encoding header with

axios.get("url", { 
    headers: { "Accept-Encoding": "gzip,deflate,compress" } 
});

This should make the response use something other than the "br" brotli compression encoding

@Flupster
Copy link

Flupster commented Dec 7, 2022

Running it in a browser works fine, problem occurs running in nodejs
Some reproduceable code:

const axios = require("axios");

axios
  .get("https://www.speedwaymotors.com/", { headers: { "Accept-Encoding": "br" } })
  .then((response) => console.log(response.data.length))
  .catch((error) => console.error(error));
cause: Error: unexpected end of file
      at BrotliDecoder.zlibOnError [as onerror] (node:zlib:189:17) {
    errno: -5,
    code: 'Z_BUF_ERROR'
  }

From a quick look I think newer versions of the Kestrel web server are compressing it differently? but curl handles it correctly

pinging @DigitalBrainJS and @jasonsaayman as this is big problem and should implement fix quick or remove v1.2.1 until it's production ready

changing https://github.com/axios/axios/blob/v1.x/lib/adapters/http.js#L430

from: streams.push(zlib.createBrotliDecompress(zlibOptions));
to: streams.push(zlib.createBrotliDecompress());

Fixes the problem

@robwilkes
Copy link

1.2.0 does indeed resolve the unexpected end of file exception, however the response data has weird encoding.
I've reverted to 1.1.3 and the response data is instead utf-8 / HTML. Seems 1.2.X is not ready for use.
image

@robutex
Copy link

robutex commented Dec 7, 2022

We have the same problem as @robwilkes: we just tried to upgrade from 1.1.3 to 1.2.1 and we got the "unexpected end of file" error thrown by the brotli decompression. We are calling a .NET 6 API from NodeJs using Axios. Version 1.1.3 works ok, 1.2.0 returns something unusable and 1.2.1 throws the error. @Flupster might be right with the Kestrel part.

@kazazor
Copy link

kazazor commented Dec 7, 2022

Same here, got the problem with 1.2.1 when using the get function.
Actually, also in 1.2.0 something is not right here and we get everything mapped to undefined.
Works fine with 1.1.3 and 1.2.0-alpha.1

@TareHimself
Copy link

TareHimself commented Dec 7, 2022

I get it while I am doing processing with an FFmpeg spawn process and a request is made with Axios, downgrading to 1.13 seems to fix it

@TomFrankly
Copy link

TomFrankly commented Dec 7, 2022

Same problem, even with an incredibly simple call:

const axios = require('axios')

async function getBulbasaur() {
  await axios.get(`https://pokeapi.co/api/v2/pokemon/1`).then((poke) => {

      console.log(poke.data.species.name)
      
    }).catch((err) => {
      console.log(err)
  })
}

getBulbasaur()

This works flawlessly on 1.1.3

Broken on 1.2.0 due to the content-header problem, broken now on 1.2.1 due to this "unexpected end of file" error.

@alisson-acioli
Copy link

I just ran into this issue with version 1.2.1. Do you have a fix planned?

@robert-calvert
Copy link

I was pulling my hair out getting the Z_BUF_ERROR thrown by Axios for otherwise successful POST requests to an external API for my Node project.

Downgrading to 1.1.3 resolved the issue.

@atulmy
Copy link
Author

atulmy commented Dec 8, 2022

This is actually third time (most of any open source library) axios broke all my production apps 😢

@AndresAusecha
Copy link

Hello

imagen

I am getting this error by trying to fetch a plain text file. Really weird

@elvisun
Copy link

elvisun commented Dec 8, 2022

I'm puzzled on how consecutive bad versions got released on such a popular library, are there more tests we could help add to prevent these?

@AndresAusecha
Copy link

I'm puzzled on how consecutive bad versions got released on such a popular library, are there more tests we could help add to prevent these?

I think we can try to get a stream from Axios response when you are not supposed to get JSON, and then process that stream. At least for me that workaround worked fine

Glazelf added a commit to Glazelf/NinigiBot that referenced this issue Dec 9, 2022
imjuni added a commit to imjuni/jin-frame that referenced this issue Dec 11, 2022
* version upgrade 3.0.1 > 3.0.2
* bundle file extension change
  * cjs/index.js > cjs/index.cjs
  * esm/index.js > esm/index.mjs
* production build apply terser
* axios version fixed: 1.1.3
  * axios/axios#5346
imjuni added a commit to imjuni/jin-frame that referenced this issue Dec 11, 2022
* version upgrade 3.0.1 > 3.0.2
* bundle file extension change
  * cjs/index.js > cjs/index.cjs
  * esm/index.js > esm/index.mjs
* production build apply terser
* axios version fixed: 1.1.3
  * axios/axios#5346
derogab added a commit to derogab/coingraph that referenced this issue Dec 11, 2022
@InspectorGadget
Copy link

InspectorGadget commented Dec 20, 2022

It works after I downgraded to 0.x. There is something going on in the newer versions (EG: 1.2.1).

@ShueiYang
Copy link

looks like the issue is still ongoing when i try to use Axios for the 1st time, I guess I will go back to the vanilla fetch method.

@ibrahiem9
Copy link

This is still an issue for me, quite surprising to see no resolution despite the module's popularity

h3poteto added a commit to h3poteto/megalodon that referenced this issue Dec 29, 2022
h3poteto added a commit to h3poteto/megalodon that referenced this issue Dec 29, 2022
Azowyl added a commit to Azowyl/coveralls-go that referenced this issue Dec 30, 2022
heyitaki added a commit to wormhole-foundation/wormhole-monitor that referenced this issue Dec 30, 2022
fixes issue described here: axios/axios#5346
SamSamskies added a commit to SamSamskies/lnurlpay that referenced this issue Jan 1, 2023
SamSamskies added a commit to SamSamskies/lnurlpay that referenced this issue Jan 1, 2023
SamSamskies added a commit to SamSamskies/lnurl-pay that referenced this issue Jan 1, 2023
@stephenwade
Copy link

This was fixed in v1.2.2.

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.