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

await axios.get() Never Resolves #4672

Open
ethan-cook opened this issue May 3, 2022 · 6 comments
Open

await axios.get() Never Resolves #4672

ethan-cook opened this issue May 3, 2022 · 6 comments

Comments

@ethan-cook
Copy link

Describe the issue

When calling axios.get() in an async function, passing in username and password authentication, intermittently the request will hang and never resolve.

Using the axios-debug-log package, I can see that Axios places the get request correctly, however, no response is ever returned. Nor is an error thrown.

This issue had also been found when using axios.get() to return an array buffer, however, I used a write stream as a temporary workaround for that case scenario.

Example Code

try {
	const { data } = await axios.get(`URL`, { auth: { username: username, password: password }});

	const images = _.filter(data.colorized, (image) => image["@primaryColorOptionCode"] == colorCode && image["@backgroundDescription"] == "Transparent" && image["@width"] == "2100");

	return images;
} catch(err) {
	this.logger.error(err.message);
	return [];
}

Expected behavior, if applicable

axios.get() to resolve its request, and return the response to the data constant.

I have tried both in Postman [9.17.1], Chrome [100.0.4896.127], and the vanilla Node.js HTTP package and was able to consistently make these GET requests. The problem only arises when utilizing Axios.

Environment

  • Axios Version [0.27.2]
  • Adapter [HTTP]
  • Browser [Chrome]
  • Browser Version [100.0.4896.127]
  • Node.js Version [17.8.0]
  • OS: Manjaro [21.2.6] and Ubuntu [lts-buster-slim]
  • Additional Library Versions Nest.js [8.0.0] axios-debug-log [0.8.4] lodash [4.17.21]

Additional context/Screenshots

@michaeljaszczuk
Copy link

I have exactly the same issue with .post method...

@Alokkumar8
Copy link

I have same issue. I'm using axios.request() method for GET request. The script just hangs after calling this method. Even calling process.exit() doesn't work if you put it after await axios.request()

@magnum6actual
Copy link

Same experience. But in a mind boggling twist - this call ran fine until today. I have no idea what changed. I did not update any packages. Now this afternoon, axios never resolves the promise of a simple get call. Same call works fine in postman.

@magnum6actual
Copy link

Well, turns out mine wasn't an Axios issue at all. I had made an unrelated change to a react component that was resulting in infinite re-render loops - so the code just never had the chance to run the promise resolution.

@vanGalilea
Copy link

I have exactly the same issue with .post method...

For us, the same behavior happens, pretty much irregularly. In most cases after the user become online again (might not be related, yet that's the only breadcrumbs we see)

@zilayo
Copy link

zilayo commented Nov 19, 2023

I've experienced the same issue which seems to happen intermittently.

The request is made, but then it fails to receive the full response and no error is thrown - the process just hangs indefinitely.

Tried debugging on a patched axios 1.6.2 with a bunch of console.logs inside lib/adapters/http > req = transport.request(options, function handleResponse(res){}):

This is a get request and the response is gzip encoded.

res.headers['content-length']; // 19521

...

let totalResponseBytes = 0;
streams[0].on('data', (chunk) => { 
totalResponseBytes += chunk.length
console.log(`on data event: ${chunk.length} bytes received. Total ${totalResponseBytes} bytes of expected total ${responseLength} bytes` received.)
}

// on data event: 16384 bytes received. Total 16384 bytes of expected total 19521 bytes received

The stream fails to then receive any further chunks. When setting a timeout in the axios config this also never seems to trigger if the first chunk has already been received (seems to be expected behavior per #5886)

If I set onDownloadProgress: (e) => {} in my axios instance then it works fine:
// on data event: 16384 bytes received. Total 16384 bytes of expected total 19521 bytes received
// on data event: 3137 bytes received. Total 19521 bytes of expected total 19521 bytes received

So for the timebeing a workaround seems to be setting an empty onDownloadProgress config option.

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

No branches or pull requests

7 participants