Skip to content

Commit da98193

Browse files
authored
Lock down server IPC address (#51378)
This attempts to avoid IPv6 and IPv4 resolve issues across network setups by locking down our internal IPC requests to just one address for consistency. This way there aren't issues when `localhost` resolves to one or the other in different cases. x-ref: #49677
1 parent ab3f707 commit da98193

3 files changed

Lines changed: 8 additions & 3 deletions

File tree

packages/next/src/server/lib/render-server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,6 @@ export async function initialize(opts: {
137137
return reject(err)
138138
}
139139
})
140-
server.listen(await getFreePort(), opts.hostname)
140+
server.listen(await getFreePort(), '0.0.0.0')
141141
})
142142
}

packages/next/src/server/lib/server-ipc/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export async function createIpcServer(
6363
)
6464

6565
const ipcPort = await new Promise<number>((resolveIpc) => {
66-
ipcServer.listen(0, server.hostname, () => {
66+
ipcServer.listen(0, '0.0.0.0', () => {
6767
const addr = ipcServer.address()
6868

6969
if (addr && typeof addr === 'object') {

packages/next/src/server/lib/server-ipc/invoke-request.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,13 @@ export const invokeRequest = async (
1818
const http = require('http') as typeof import('http')
1919

2020
try {
21+
// force to 127.0.0.1 as IPC always runs on this hostname
22+
// to avoid localhost issues
23+
const parsedTargetUrl = new URL(targetUrl)
24+
parsedTargetUrl.hostname = '127.0.0.1'
25+
2126
const invokeReq = http.request(
22-
targetUrl,
27+
parsedTargetUrl.toString(),
2328
{
2429
headers: invokeHeaders,
2530
method: requestInit.method,

0 commit comments

Comments
 (0)