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

Bun TCP Sockets refuse to connect with hostname as "localhost" #7158

Closed
PranjalAgni opened this issue Nov 16, 2023 · 3 comments
Closed

Bun TCP Sockets refuse to connect with hostname as "localhost" #7158

PranjalAgni opened this issue Nov 16, 2023 · 3 comments
Labels
bug Something isn't working bun.js Something to do with a Bun-specific API

Comments

@PranjalAgni
Copy link

PranjalAgni commented Nov 16, 2023

What version of Bun is running?

1.0.11+f7f6233ea

What platform is your computer?

Darwin 23.1.0 x86_64 i386

What steps can reproduce the bug?

I wrote a simple TCP server and client just to try the new API but client refuses(ECONNREFUSED) to connect when I set hostname as localhost in the server. Sharing the code that I am running:

server.ts

Bun.listen<SocketData>({
  hostname: "localhost",
  port: 4000,
  socket: {
    data(socket, data) {
      console.log("Ack: ", socket.data.sessionId);
      console.log("Client says: ", data.toString());
    }, // message received from client
    open(socket) {
      console.log("Client connected");
      socket.data = {
        sessionId: randomUUID(),
      };
      socket.write(socket.data.sessionId);
    }, // socket opened
    close(socket) {
      console.log("Client disconnected");
    }, // socket closed

  },
});

client.ts

Bun.connect({
  hostname: "localhost",
  port: 4000,
  socket: {
    data(socket, data) {
      console.log("Got data from server: ", data.toString());
    },
  },
});

Output:
image

But as soon as I set the hostname as 127.0.0.1 on the server side it starts to work fine and socket connection/data exchange is getting made.

What is the expected behavior?

Socket connection should be made irrespective of the hostname is set localhost or 127.0.0.1

What do you see instead?

No response

Additional information

No response

@PranjalAgni PranjalAgni added the bug Something isn't working label Nov 16, 2023
@PranjalAgni PranjalAgni changed the title Bun TCP Sockets refuse to connect with "localhost" Bun TCP Sockets refuse to connect with hostname as "localhost" Nov 16, 2023
@Electroid Electroid added the bun.js Something to do with a Bun-specific API label Nov 16, 2023
@Electroid
Copy link
Contributor

Possibly related: #1425

@PranjalAgni
Copy link
Author

I updated the docs for now, so the TCP sockets example works #7188

@Jarred-Sumner
Copy link
Collaborator

This was fixed by happy eyeballs #11206

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working bun.js Something to do with a Bun-specific API
Projects
None yet
Development

No branches or pull requests

3 participants