nodejs / help

:sparkles: Need help with Node.js? File an Issue here. :rocket:
1.47k stars 282 forks source link

Local network connection timeout on macOS Ventura #4192

Closed RollinRolanding closed 1 year ago

RollinRolanding commented 1 year ago

Details

I am running a simple Node server (on M2 Max Macbook 10.0.0.207, Node v18.16.1) listening on all interfaces but cannot connect to it from other devices (tried iPhone and another Macbook [10.0.0.78]). I can access the server on the machine it is running, 10.0.0.207. I have tried running a Python3 server listening on the same port (Uvicorn running on http://0.0.0.0:3000) and it is accessible from the iPhone and Macbook. I do not think it's related to my network, it seems related to Node and macOS

When the 10.0.0.78 devices attempts to connect I see the following in Wireshark:

image

On the machine running the server, the firewall allows node to accept incoming (I have tried turning the firewall off, it does not resolve the issue):

image

I have tried reinstalled node, it does not resolve the issue.

I have also tried different servers, like a Metro server, and the simple Node server below which logs the following on startup:

NODE_DEBUG=net node nodetest.js
NET 4254: setupListenHandle 0.0.0.0 3000 4 false undefined
NET 4254: setupListenHandle: create a handle
NET 4254: bind to 0.0.0.0
Server running at http://0.0.0.0:3000/

And lsof reports: node 4266 rolland 23u IPv4 0x6a8e48f63eab0429 0t0 TCP *:3000 (LISTEN)

Any help would be greatly appreciated.

Node.js version

{ node: '18.16.1', acorn: '8.8.2', ada: '1.0.4', ares: '1.19.1', brotli: '1.0.9', cldr: '42.0', icu: '72.1', llhttp: '6.0.11', modules: '108', napi: '8', nghttp2: '1.52.0', nghttp3: '0.7.0', ngtcp2: '0.8.1', openssl: '3.0.9+quic', simdutf: '3.2.2', tz: '2022g', undici: '5.21.0', unicode: '15.0', uv: '1.44.2', uvwasi: '0.0.15', v8: '10.2.154.26-node.26', zlib: '1.2.13' }

Example code

const http = require('http');

const hostname = '0.0.0.0';
const port = 3000;

const server = http.createServer((req, res) => {
  res.statusCode = 200;
  res.setHeader('Content-Type', 'text/plain');
  res.end('Hello World');
});

server.listen(port, hostname, () => {
  console.log(`Server running at http://${hostname}:${port}/`);
});

Operating system

macOS Ventura 13.2.1

Scope

Server accessibility

Module and version

Not applicable.

preveen-stack commented 1 year ago

can you substitute the ip for 0.0.0.0 and try once

preveen-stack commented 1 year ago

I just tried on my macbookpro with some modification to print the incoming ip. worked fine for me

const http = require('http');

const server = http.createServer((req, res) => {
  const clientIp = req.connection.remoteAddress;
  console.log(`Received request from IP: ${clientIp}`);

  res.statusCode = 200;
  res.setHeader('Content-Type', 'text/plain');
  res.end('Hello, World!');
});

const port = 3000;
const hostname = '0.0.0.0';

server.listen(port, hostname, () => {
  console.log(`Server running at http://${hostname}:${port}/`);
});

console log

Server running at http://0.0.0.0:3000/
Received request from IP: 192.168.43.1
Received request from IP: 192.168.43.1
Received request from IP: 192.168.43.1
Received request from IP: 192.168.43.1
{
  node: '18.7.0',
  v8: '10.2.154.13-node.9',
  uv: '1.43.0',
  zlib: '1.2.11',
  brotli: '1.0.9',
  ares: '1.18.1',
  modules: '108',
  nghttp2: '1.47.0',
  napi: '8',
  llhttp: '6.0.7',
  openssl: '3.0.5+quic',
  cldr: '41.0',
  icu: '71.1',
  tz: '2022a',
  unicode: '14.0',
  ngtcp2: '0.1.0-DEV',
  nghttp3: '0.1.0-DEV'
}
RollinRolanding commented 1 year ago

@preveen-stack Yes I can! So changed 0.0.0.0 to 10.0.0.207:

NODE_DEBUG=net node nodetest.js
NET 2493: setupListenHandle 10.0.0.207 3000 4 false undefined
NET 2493: setupListenHandle: create a handle
NET 2493: bind to 10.0.0.207
Server running at http://10.0.0.207:3000/

Issue persists. Wireshark looks identical from what I can tell.

RollinRolanding commented 1 year ago

I also updated macOS Ventura to 13.4.1 to see if that might've been related, issue persists (Python3 connectable, firewall allows Node [even off, issue persists], etc.)

preveen-stack commented 1 year ago

BTW my macbook pro is intel and not M1/M2