Viki 写东西的地方


Record Axios's `Z_BUF_ERROR` BUG

In version 1.2.0 of Axios, many people encountered the Z_BUF_ERROR bug.

When the Content-Encoding request header is set, but the returned content is empty (such as a 204 request, HEAD request, or redirect request), Axios still calls zlib's BrotliDecoder for Brotli decompression, causing an error in zlib. You can refer to this issue.

Subsequently, the developers fixed this issue and also fixed the case where the response header does not have Content-Length.

For some reason, the core developers of Axios are sensitive to releases (refer to this comment and this issue). Finally, under the repeated anticipation of the community, version 1.2.1 was also released.

However, the good times didn't last long. The Z_BUF_ERROR issue reappeared in version 1.2.1. After flipping through a few pages of issues, the cause of the error was roughly identified: in the previous fix for the "case where the response header does not have Content-Length" commit, a BUG in Brotli decompression was triggered. When the compression format of the data returned by the server is br, it will cause a Z_BUF_ERROR error. As a temporary solution, you can manually set the request header to specify the encoding format returned by the server and ensure that br is not returned, as shown below.

axios.get(someApi, {
  headers: { 'Accept-Encoding': 'gzip,deflate,compress' }

This issue has already been fixed, but it hasn't been released yet =.=, as mentioned earlier. Although it hasn't been released yet, I saw a release PR yesterday (2022/12/24, just happened to be Christmas Eve), hoping to release it as soon as possible. It has been three weeks since the last version was released. After all, a library with such high visibility will accumulate more problems if the latest version with broken bugs exists for such a long time, and to be honest, it has a very wide impact.

While flipping through the issues, I saw quite a few impolite comments, giving a feeling of "if you write a bug, you have to update it quickly and release it quickly". Complaints aside, I still hope that there can be more understanding and tolerance between maintainers and users in the open-source community.

Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.