oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
74.49k stars 2.79k forks source link

`node:net` client sockets remoteAddress property return the local address instead of the remote address #4660

Open cfal opened 1 year ago

cfal commented 1 year ago

What version of Bun is running?

1.0

What platform is your computer?

Linux x86_64

What steps can reproduce the bug?

Bun returns the local server address instead of the remote address.

import net from 'net'

const server = net.createServer((socket) => {
    console.log('New connection from ' + socket.remoteAddress + ':' + socket.remotePort);
});

server.listen(9292, '0.0.0.0', () => {
    console.log('TCP server listening on 0.0.0.0:9292');
});
$ bun main.js 
TCP server listening on 0.0.0.0:9292
New connection from <server address>:9292
$ node main.js 
TCP server listening on 0.0.0.0:9292
New connection from <client address>:37862

What is the expected behavior?

The connecting client's address

What do you see instead?

The local server address

Additional information

No response

SuperAuguste commented 1 year ago

I'm working on this :)

uSockets doesn't actually implement a remotePort function so Bun instead (incorrectly) passes the local port in #attach in its net shim, so I'll implement everything from uSockets up. :)

nektro commented 7 months ago

this appears to be working now. are you able to confirm?