Unverified Commit ad0c5bb0 authored by Tommy D. Rossi's avatar Tommy D. Rossi Committed by GitHub

Use POST for invokeIpcMethod (#65238)

args can be arbitrarily big, even MBs of data. But an url has a limit,
in Node.js it's 15Kb. This will cause the Node.js server to fail with
ECONNRESET

Fixes: https://github.com/vercel/next.js/issues/56005
Partially fix ECONNRESET errors in
https://github.com/vercel/next.js/issues/57491

---------
Co-authored-by: 's avatarJJ Kasper <jj@jjsweb.site>
parent 68d5a389
......@@ -30,7 +30,25 @@ export async function createIpcServer(
}
const method = url.searchParams.get('method')
const args: any[] = JSON.parse(url.searchParams.get('args') || '[]')
let body = await new Promise<string>((resolve, reject) => {
let str = ''
req.on('data', (chunk) => {
str += chunk
})
req.on('end', () => {
resolve(str)
})
req.on('error', (err) => {
reject(err)
})
res.on('close', function () {
let aborted = !res.writableFinished
if (aborted) {
reject(new Error('ipc request aborted'))
}
})
})
const args: any[] = JSON.parse(body || '[]')
if (!method || !Array.isArray(args)) {
return res.end()
......
......@@ -9,7 +9,7 @@ export const invokeRequest = async (
method: IncomingMessage['method']
signal?: AbortSignal
},
readableBody?: Readable | ReadableStream
readableBody?: string | Readable | ReadableStream
) => {
const invokeHeaders = filterReqHeaders(
{
......
......@@ -47,11 +47,12 @@ export async function invokeIpcMethod({
const res = await invokeRequest(
`http://${fetchHostname}:${ipcPort}?key=${ipcKey}&method=${
method as string
}&args=${encodeURIComponent(JSON.stringify(args))}`,
}`,
{
method: 'GET',
method: 'POST',
headers: {},
}
},
JSON.stringify(args)
)
const body = await res.text()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment