Unverified Commit 637b8cfa authored by Jimmy Miller's avatar Jimmy Miller Committed by GitHub

Add in warning for workers around the fsevents bug (#98447)

We removed this because we fixed the original crashes. This crash does
not happen out of the box. But it isn't hard to trigger with plugins.
And we'd rather not have people experience this without being explicit.
parent 393de1eb
...@@ -376,7 +376,7 @@ export const experimentalSchema = { ...@@ -376,7 +376,7 @@ export const experimentalSchema = {
.union([z.literal(false), z.literal('full'), z.literal('auto')]) .union([z.literal(false), z.literal('full'), z.literal('auto')])
.optional(), .optional(),
turbopackPluginRuntimeStrategy: z turbopackPluginRuntimeStrategy: z
.enum(['workerThreads', 'childProcesses']) .enum(['workerThreads', 'childProcesses', 'forceWorkerThreads'])
.optional(), .optional(),
turbopackMinify: z turbopackMinify: z
.union([ .union([
......
...@@ -787,9 +787,18 @@ export interface ExperimentalConfig { ...@@ -787,9 +787,18 @@ export interface ExperimentalConfig {
* *
* `'workerThreads'` runs the same work in worker threads instead, which should * `'workerThreads'` runs the same work in worker threads instead, which should
* use less memory and CPU. It may become the default in a future version of * use less memory and CPU. It may become the default in a future version of
* Next.js. * Next.js. On Node.js 24.13.1 and newer, a Node.js teardown bug can abort the
*/ * process when a native addon has a live Node-API threadsafe function as a
turbopackPluginRuntimeStrategy?: 'workerThreads' | 'childProcesses' * worker exits. Next.js falls back to `'childProcesses'` on affected versions.
* See <https://github.com/nodejs/node/issues/65100>.
*
* `'forceWorkerThreads'` bypasses this fallback. It may cause the process to
* abort on affected Node.js versions.
*/
turbopackPluginRuntimeStrategy?:
| 'workerThreads'
| 'childProcesses'
| 'forceWorkerThreads'
/** /**
* Enable minification. Defaults to true in build mode and false in dev mode. * Enable minification. Defaults to true in build mode and false in dev mode.
......
...@@ -3,6 +3,7 @@ import { createRequire } from 'module' ...@@ -3,6 +3,7 @@ import { createRequire } from 'module'
import { basename, extname, join, relative, isAbsolute, resolve } from 'path' import { basename, extname, join, relative, isAbsolute, resolve } from 'path'
import { pathToFileURL } from 'url' import { pathToFileURL } from 'url'
import findUp from 'next/dist/compiled/find-up' import findUp from 'next/dist/compiled/find-up'
import semver from 'next/dist/compiled/semver'
import * as Log from '../build/output/log' import * as Log from '../build/output/log'
import * as ciEnvironment from '../server/ci-info' import * as ciEnvironment from '../server/ci-info'
import { import {
...@@ -1690,6 +1691,49 @@ function assignDefaultsAndValidate( ...@@ -1690,6 +1691,49 @@ function assignDefaultsAndValidate(
result.experimental.useCache = result.cacheComponents result.experimental.useCache = result.cacheComponents
} }
const pluginRuntimeStrategy =
result.experimental.turbopackPluginRuntimeStrategy
if (
pluginRuntimeStrategy === 'workerThreads' ||
pluginRuntimeStrategy === 'forceWorkerThreads'
) {
result.experimental.turbopackPluginRuntimeStrategy = 'workerThreads'
if (!process.versions.bun && !process.versions.deno) {
const nodeVersion = process.versions.node
const affectedNodeRange = '>=24.13.1'
if (
semver.satisfies(nodeVersion, affectedNodeRange, {
includePrerelease: true,
})
) {
if (pluginRuntimeStrategy === 'forceWorkerThreads') {
Log.warn(
`\`experimental.turbopackPluginRuntimeStrategy = ` +
`'forceWorkerThreads'\` is enabled, bypassing protection ` +
`against a known potential crash in Node.js ${affectedNodeRange}.\n` +
`A Node.js worker-thread teardown bug can abort the process ` +
`when a native addon, such as fsevents, has a live Node-API ` +
`threadsafe function as a worker exits.\n` +
`See https://github.com/nodejs/node/issues/65100.`
)
} else {
Log.warn(
`\`experimental.turbopackPluginRuntimeStrategy = ` +
`'workerThreads'\` is disabled on Node.js ${nodeVersion}.\n` +
`A Node.js worker-thread teardown bug can abort the process ` +
`when a native addon, such as fsevents, has a live Node-API ` +
`threadsafe function as a worker exits.\n` +
`See https://github.com/nodejs/node/issues/65100.\n` +
`Falling back to 'childProcesses'. To override at your own ` +
`risk, use 'forceWorkerThreads'.`
)
result.experimental.turbopackPluginRuntimeStrategy = 'childProcesses'
}
}
}
}
// Store the distDirRoot in the config before it is modified for development mode // Store the distDirRoot in the config before it is modified for development mode
;(result as NextConfigComplete).distDirRoot = result.distDir ;(result as NextConfigComplete).distDirRoot = result.distDir
......
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