Skip to content

Commit 5e7a2de

Browse files
bram-atmireclaude
andcommitted
Fix PM2 cluster mode ECONNREFUSED errors
Node.js 17+ changed DNS resolution to prefer IPv6 over IPv4. When running in PM2 cluster mode, this causes "ECONNREFUSED ::1:8080" errors if the backend only listens on IPv4 (127.0.0.1). This fix sets dns.setDefaultResultOrder('ipv4first') at the very start of the SSR bootstrap to ensure localhost resolves to IPv4. See: nodejs/node#40537 🤖 Generated with [Claude Code](https://claude.ai/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent c2258bf commit 5e7a2de

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

src/main.server.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
/**
2+
* Fix for Node.js 17+ where DNS resolution prefers IPv6 over IPv4.
3+
* This causes "ECONNREFUSED ::1:8080" errors in PM2 cluster mode when
4+
* the backend only listens on IPv4.
5+
* See: https://github.com/nodejs/node/issues/40537
6+
*/
7+
import * as dns from 'node:dns';
8+
dns.setDefaultResultOrder('ipv4first');
9+
110
import 'core-js/es/reflect';
211
import 'zone.js';
312
import 'reflect-metadata';

0 commit comments

Comments
 (0)