Unverified Commit 1356088d authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Update static build workers (#46705)

Ensures we log when a static build worker exits unexpectedly and fixes
passing down `NODE_OPTIONS` unconditionally as this can cause too much
memory to be leveraged when it shouldn't be.

x-ref: [slack
thread](https://vercel.slack.com/archives/C04S835KUC9/p1677788484200189)

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have a helpful link attached, see
[`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)
parent 8416b70f
import { ChildProcess } from 'child_process'
import { Worker as JestWorker } from 'next/dist/compiled/jest-worker' import { Worker as JestWorker } from 'next/dist/compiled/jest-worker'
import { getNodeOptionsWithoutInspect } from '../server/lib/utils'
type FarmOptions = ConstructorParameters<typeof JestWorker>[1] type FarmOptions = ConstructorParameters<typeof JestWorker>[1]
const RESTARTED = Symbol('restarted') const RESTARTED = Symbol('restarted')
...@@ -24,11 +25,38 @@ export class Worker { ...@@ -24,11 +25,38 @@ export class Worker {
this._worker = undefined this._worker = undefined
const createWorker = () => { const createWorker = () => {
this._worker = new JestWorker(workerPath, farmOptions) as JestWorker this._worker = new JestWorker(workerPath, {
...farmOptions,
forkOptions: {
...farmOptions.forkOptions,
env: {
...((farmOptions.forkOptions?.env || {}) as any),
...process.env,
// we don't pass down NODE_OPTIONS as it can
// extra memory usage
NODE_OPTIONS: getNodeOptionsWithoutInspect()
.replace(/--max-old-space-size=[\d]{1,}/, '')
.trim(),
} as any,
},
}) as JestWorker
restartPromise = new Promise( restartPromise = new Promise(
(resolve) => (resolveRestartPromise = resolve) (resolve) => (resolveRestartPromise = resolve)
) )
for (const worker of ((this._worker as any)._workerPool?._workers ||
[]) as {
_child: ChildProcess
}[]) {
worker._child.on('exit', (code, signal) => {
if (code || signal) {
console.error(
`Static worker unexpectedly exited with code: ${code} and signal: ${signal}`
)
}
})
}
this._worker.getStdout().pipe(process.stdout) this._worker.getStdout().pipe(process.stdout)
this._worker.getStderr().pipe(process.stderr) this._worker.getStderr().pipe(process.stderr)
} }
......
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