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 request fails when setting maxRedirects to 0 #4871

Closed
JeremyFunk opened this issue Sep 11, 2023 · 4 comments
Closed

Axios request fails when setting maxRedirects to 0 #4871

JeremyFunk opened this issue Sep 11, 2023 · 4 comments
Assignees
Labels
bug Something isn't working

Comments

@JeremyFunk
Copy link
Contributor

What version of Bun is running?

1.0.0

What platform is your computer?

Darwin 22.4.0 arm64 arm

What steps can reproduce the bug?

Execute this code:

  • For Bun run bun index.ts
  • For Node run node.index.ts

Then, change maxRedirects to 1 and repeat.

import axios from 'axios'

let isResolved = false
;(async () => {
  try {
    return await axios.get('https://example.com', { maxRedirects: 0 })
  } catch {
    return 'error'
  }
})().then(_ => (isResolved = true))

setInterval(() => {
  if (isResolved) {
    console.log('resolved')
    process.exit(0)
  } else {
    console.log('not resolved')
  }
}, 1000)

What is the expected behavior?

NodeJS and Bun should behave the same way. That is, if maxRedirects is set to 0, the request should not silently stall.

What do you see instead?

Bun and Node are behaving the same way when running with maxRedirects >=1. At maxRedirects = 0 NodeJS can execute the code with no issue while Bun silently stalls (infinitely waits for the promise to be resolved).

Additional information

I tested with multiple axios versions. The snippet above was written with version 1.5.0

@JeremyFunk JeremyFunk added the bug Something isn't working label Sep 11, 2023
@JeremyFunk JeremyFunk changed the title Axios request fails when setting maxRedirects to 1 Axios request fails when setting maxRedirects to 0 Sep 11, 2023
@seanwessmith
Copy link

@JeremyFunk this runs on Bun@1.0.1

@Hanaasagi
Copy link
Collaborator

Hanaasagi commented Sep 22, 2023

This issue can be reproduced in 1.0.3. I see that when maxRedirects is set to 0, it uses node:http as the transport. That is the difference.

https://github.com/axios/axios/blob/4c89f25196525e90a6e75eda9cb31ae0a2e18acd/lib/adapters/http.js#L409-L424

The following code will hang in bun

import axios from "axios";
import http from "node:http";

const resp = await axios.get("http://example.com", { transport: http });
console.log(resp.data);

Env

  • bun 1.0.3+9d5459221ff663b6c0058440167e098886d97cc2
  • axios 1.5.0
  • follow-redirects: 1.15.3

Update:

After some debugging,

https://github.com/axios/axios/blob/4c89f25196525e90a6e75eda9cb31ae0a2e18acd/lib/adapters/http.js#L439

I found req.destroyed is true in bun but false in nodejs.

import http from "node:http";

const req = http.request("http://example.com", (res) => {
  console.log("req.destroyed", req.destroyed);
  res.on("data", (data) => {
    // console.log(`Received response: ${data}`);
  });

  res.on("end", () => {
    // console.log("Request finished.");
  });
});

req.end();

@nektro
Copy link
Contributor

nektro commented May 25, 2024

does this still reproduce for you? it appears to be working on my end in Bun 1.1.10 (you may need to run bun upgrade)

many axios fixes made it into Bun 1.1.8# and Bun 1.1.9#.

@nektro nektro self-assigned this May 25, 2024
@seanwessmith
Copy link

sweet, axios and this test case as well work now!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants