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

Axios not receiving 204 response with Transfer-Encoding header in Node v14 #3473

Open
joshuas2020 opened this issue Dec 11, 2020 · 18 comments
Open
Projects

Comments

@joshuas2020
Copy link

Describe the bug

After upgrading our node version to v14.15.1 our Axios requests in our express server never receive a response from an endpoint that returns 204 with header: 'Transfer-Encoding': 'chunked'.
I know we should not be receiving this (see here) but we do not have control of this endpoint.

Previously when we were on v10.23.0 of node we had no problem with receiving these responses.

I have tried the same request with the request library and am able to receive a response. See example below.

To Reproduce

Created a simple express server to demonstrate.

npm install axios express request

With the following index.js

Sending a GET request to http://localhost:8555/request will return 200 OK, whereas the request to http://localhost:8555/ will timeout/never receive a response.

const express = require('express');
const axios = require('axios');
const request = require('request');

const httpPort = 8555;

const app = express();

app.get('/', async (req, res, next) => {
  try {
    const result = await axios.get(`http://localhost:${httpPort}/sample-upstream-response`, {
      timeout: 10000,
    });
    res.send(result.data);
  } catch (error) {
    res.sendStatus(500);
  }
});

app.get('/request', (req, res, next) => {
  request(`http://localhost:${httpPort}/sample-upstream-response`, { json: true }, (err, response, body) => {
    if (err) { 
      return res.sendStatus(500);
    }
    res.send(body);
  });
});

app.get('/sample-upstream-response', (req, res, next) => {
  res.writeHead(204, {
    'Transfer-Encoding': 'chunked',
  });
  res.end();
});

app.listen(httpPort, () => {
  console.log(`INFO: listening on http://localhost:${httpPort}`);
});

Expected behavior

I am expecting that Axios should be able to receive the response from this server. Or I should be able to change some axios config to be able to receive this response.

Environment

  • Axios Version 0.21.0
  • Node.js Version 14.15.1
  • OS: Windows 10, ubuntu 18.04
  • Additional Library Versions express 4.17.1, request 2.88.2

Additional context/Screenshots

@lalithkumart
Copy link

Yes, Same issue i am also facing with Node v14

After upgrading to v14, i am not getting response back in UI. However the node js sending the response (debugged till last step).

Also, if i hit the api via postman, it is getting response.
Also if i hit this api via "Open Link in New Tab" option click, then also getting response back

Only in the application (where i am using axios), the response is not coming back. The status in console is keep on "Pending".

@DaWoCX
Copy link

DaWoCX commented Jan 25, 2021

I'm facing the same problem.

With Postman / Soap UI I get a response but in my application the response gets lost in case of status code 204.

Used Versions:

  • node.js: v14.13.0
  • axios: 0.21.0

Used OS: Windows 10

@VassilAtanasov
Copy link

VassilAtanasov commented Mar 17, 2021

The problem (hanging after the call) was spotted when Axios (any version) on node 14 calls node red api runnung on node 12.
An workaround is to change your applications to use http 200 instead of 204 status codes.

@jasonsaayman
Copy link
Member

Hi,

I think the major issue is that Axios is not very stable on v14. I am planning to work on that and then a v16 as soon as it lands in April.

Thanks

@jasonsaayman jasonsaayman added this to To do in v1.0.0 via automation Mar 17, 2021
@jasonsaayman jasonsaayman added this to the v1.0.0 milestone Mar 17, 2021
@jasonsaayman jasonsaayman self-assigned this Mar 17, 2021
@ryutamaki
Copy link

I have same issue.
As an additional information, it is happening when we return any body along with status code 204.

node v14.15.3
axios 0.21.1

@TrojanRocks
Copy link

I'm facing same issue, for me it's happening with no content in response for status code 204

axios version 0.21.1

@AminFazlMondo
Copy link

Is there a timeframe that this might get fixed?

@cucupac
Copy link

cucupac commented Feb 11, 2022

@joshuas2020 @VassilAtanasov Any update on this? Is anyone able to receive 204s?

@joshuas2020
Copy link
Author

Hi @AdamCuculich
I just retried the above example with axios 0.26.0 and am now receiving an error: 'ERR_REQUEST_ABORTED'
I guess this is due to it expecting a chunked response but there being no data?

@cucupac
Copy link

cucupac commented Apr 21, 2022

Yes, it happens when no response body is received. My temporary solution was to just replace 204s with 200s -- not ideal, but it works.

@AnjaneyuluBatta505
Copy link

AnjaneyuluBatta505 commented Apr 26, 2022

It's the issue with API response for me i.e fastapi tiangolo/fastapi#2832.
After fixing the response then it worked.

Check for the following in your API response.

status code: 204
response body: ''

response body should be empty

@christianallred
Copy link

Is this going to be addressed? this ticket has been open for 2 years

@jasonsaayman jasonsaayman removed this from the v1.0.0 milestone Jun 12, 2022
@jasonsaayman jasonsaayman removed their assignment Jun 14, 2022
@tregonzalesCar
Copy link

is this being addressed elsewhere?

@EmadMirzaieR
Copy link

It was very painful. I wasted my time on this.

@tregonzalesCar
Copy link

@jasonsaayman is this addressed in any new axios versions?

@cucupac
Copy link

cucupac commented Sep 14, 2022

For me, the issue was that a 204 expects no content in the response, but I believe my 204 was sending "null" as a response, which was tripping up axios. For those in a similar boat, ensure that the response doesn't have a response body at all. It should work then.

@brinobruno
Copy link

Facing same issue, 200 followed by a 204, on Insomnia everything works fine, it's a simple node-react request with axios

@andrerocker
Copy link

andrerocker commented Oct 25, 2023

Samething here!

  • backend: quarkus resteasy
  • frontend: react axios 1.5.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
v1.0.0
  
To do
Development

No branches or pull requests