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/fetch stalls program #5642

Closed
callumok2004 opened this issue Sep 17, 2023 · 11 comments
Closed

axios/fetch stalls program #5642

callumok2004 opened this issue Sep 17, 2023 · 11 comments
Labels
bug Something isn't working memory leak needs repro Needs an example to reproduce

Comments

@callumok2004
Copy link

callumok2004 commented Sep 17, 2023

What version of Bun is running?

Tried on 1.0.2 and 1.0.3+25aa51dfc4976d1477d2714e5742393f190dc39f

What platform is your computer?

Linux 5.4.0-155-generic x86_64 x86_64

What steps can reproduce the bug?

On WSL, everything seems to work just fine, but when I use my linux server, this does not work with bun, with with node everything runs just fine.

export const DefaultOptions = {
  http: {
    api: "https://discord.com/api",
    version: "10"
  }
};

export const Endpoints = {
  botGateway: "/gateway/bot"
};
//
export async function fetchGatewayInformation(token: string, guildsPerShard = 1000) {
  if (!token) throw new Error("DISCORD_TOKEN_MISSING");

  console.log("Fetching gateway information..."); // This logs
  const data = await fetch(`${DefaultOptions.http.api}/v${DefaultOptions.http.version}${Endpoints.botGateway}`, {
    headers: { Authorization: `Bot ${token.replace(/^Bot\s*/i, "")}`, "Accept-Encoding": "gzip,deflate,compress" }
  }).then(res => res.json());
  console.log("Fetched gateway information."); // This does not log.

  return {
    shards: Math.ceil((data.shards * 1000) / guildsPerShard),
    session_start_limit: data.session_start_limit
  };
}

I am also seeing this in my console which suggests the request was successful.
image

While it halts on the request, memory usage quickly increases until it eventually reaches the memory limit
image

What is the expected behavior?

Expecting a response, and for the code to continue as normal

What do you see instead?

The code halts when making fetch/axios requests

Additional information

I am unsure if this is something I am doing wrong myself, or an issue with bun, but I believe it could be bun as running the same code on node works as expected. It's also weird how it works fine on WSL but not on the server

@callumok2004 callumok2004 added the bug Something isn't working label Sep 17, 2023
@callumok2004 callumok2004 changed the title Awaiting axios/fetch stalls program axios/fetch stalls program Sep 17, 2023
@Electroid Electroid added node.js Compatibility with Node.js APIs crash An issue that could cause a crash and removed node.js Compatibility with Node.js APIs labels Sep 17, 2023
@Electroid
Copy link
Contributor

Sorry that is happening, we'll take a look.

@callumok2004
Copy link
Author

Adding this screenshot to show what happens between WSL and linux server, tested on latest release
image

@akoenig
Copy link

akoenig commented Oct 3, 2023

I can also confirm (1.0.3) that performing multiple fetch requests leads to a stalled process. The first request is successful, but the next (same) request never resolves.

@Jarred-Sumner
Copy link
Collaborator

I can also confirm (1.0.3) that performing multiple fetch requests leads to a stalled process. The first request is successful, but the next (same) request never resolves.

Can you try in canary? bun upgrade --canary

We made some changes to something related to this

@callumok2004
Copy link
Author

I can also confirm (1.0.3) that performing multiple fetch requests leads to a stalled process. The first request is successful, but the next (same) request never resolves.

Can you try in canary? bun upgrade --canary

We made some changes to something related to this

Hey, just tested this and sadly I am not seeing any difference

@akoenig
Copy link

akoenig commented Oct 3, 2023

@Jarred-Sumner, tested with the current canary and it is the same problem. Can break it down a little bit. Looks like it only fails when communicating with a private IP address (e.g. 10.12.0.50 / "Class A"). Hope that helps in any way :)

@akoenig
Copy link

akoenig commented Oct 3, 2023

@Jarred-Sumner One addition: Not sure if it is related to private IP addresses anymore. When performing the request via curl, I can see that the server closes the connection before the actual response was fully consumed. The curl -v looks like:

"timestamp": 1234567 }
* Closing connection 0
]}%

Somehow processing the response fails when there was a "connection closed" event before. It doesn't happen when I curl a HTTP server where the Connection #0 to host x.x.x.x left intact. Such a request also works in the bun fetch implementation.

Edit: Gone back in the version history and it looks like it is a "regression" between 0.8.1...1.0.0 as 0.8.1 works as expected.

@zomchak-code
Copy link

Related to #7260

@hoskin
Copy link

hoskin commented Feb 19, 2024

+1, this is making it impossible to use the popular twilio library.

@terminal-ator
Copy link

+1, this is making it impossible to use the popular twilio library.

Hey, has there been any solution to this?

@nektro nektro added needs repro Needs an example to reproduce memory leak and removed crash An issue that could cause a crash labels Oct 22, 2024
Copy link
Contributor

Hello @callumok2004. Please provide a minimal reproduction using a GitHub repository, Replit, CodeSandbox, or provide a bulleted list of commands to run that reproduce this issue. Issues marked with needs repro will be closed if they have no activity within 3 days.

@callumok2004 callumok2004 closed this as not planned Won't fix, can't repro, duplicate, stale Jan 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working memory leak needs repro Needs an example to reproduce
Projects
None yet
Development

No branches or pull requests

8 participants