Skip to content

Commit 637b8cf

Browse files
authored
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.
1 parent 393de1e commit 637b8cf

3 files changed

Lines changed: 57 additions & 4 deletions

File tree

‎packages/next/src/server/config-schema.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ export const experimentalSchema = {
376376
.union([z.literal(false), z.literal('full'), z.literal('auto')])
377377
.optional(),
378378
turbopackPluginRuntimeStrategy: z
379-
.enum(['workerThreads', 'childProcesses'])
379+
.enum(['workerThreads', 'childProcesses', 'forceWorkerThreads'])
380380
.optional(),
381381
turbopackMinify: z
382382
.union([

‎packages/next/src/server/config-shared.ts‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -787,9 +787,18 @@ export interface ExperimentalConfig {
787787
*
788788
* `'workerThreads'` runs the same work in worker threads instead, which should
789789
* use less memory and CPU. It may become the default in a future version of
790-
* Next.js.
791-
*/
792-
turbopackPluginRuntimeStrategy?: 'workerThreads' | 'childProcesses'
790+
* Next.js. On Node.js 24.13.1 and newer, a Node.js teardown bug can abort the
791+
* process when a native addon has a live Node-API threadsafe function as a
792+
* worker exits. Next.js falls back to `'childProcesses'` on affected versions.
793+
* See <https://github.com/nodejs/node/issues/65100>.
794+
*
795+
* `'forceWorkerThreads'` bypasses this fallback. It may cause the process to
796+
* abort on affected Node.js versions.
797+
*/
798+
turbopackPluginRuntimeStrategy?:
799+
| 'workerThreads'
800+
| 'childProcesses'
801+
| 'forceWorkerThreads'
793802

794803
/**
795804
* Enable minification. Defaults to true in build mode and false in dev mode.

‎packages/next/src/server/config.ts‎

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { createRequire } from 'module'
33
import { basename, extname, join, relative, isAbsolute, resolve } from 'path'
44
import { pathToFileURL } from 'url'
55
import findUp from 'next/dist/compiled/find-up'
6+
import semver from 'next/dist/compiled/semver'
67
import * as Log from '../build/output/log'
78
import * as ciEnvironment from '../server/ci-info'
89
import {
@@ -1690,6 +1691,49 @@ function assignDefaultsAndValidate(
16901691
result.experimental.useCache = result.cacheComponents
16911692
}
16921693

1694+
const pluginRuntimeStrategy =
1695+
result.experimental.turbopackPluginRuntimeStrategy
1696+
if (
1697+
pluginRuntimeStrategy === 'workerThreads' ||
1698+
pluginRuntimeStrategy === 'forceWorkerThreads'
1699+
) {
1700+
result.experimental.turbopackPluginRuntimeStrategy = 'workerThreads'
1701+
1702+
if (!process.versions.bun && !process.versions.deno) {
1703+
const nodeVersion = process.versions.node
1704+
const affectedNodeRange = '>=24.13.1'
1705+
if (
1706+
semver.satisfies(nodeVersion, affectedNodeRange, {
1707+
includePrerelease: true,
1708+
})
1709+
) {
1710+
if (pluginRuntimeStrategy === 'forceWorkerThreads') {
1711+
Log.warn(
1712+
`\`experimental.turbopackPluginRuntimeStrategy = ` +
1713+
`'forceWorkerThreads'\` is enabled, bypassing protection ` +
1714+
`against a known potential crash in Node.js ${affectedNodeRange}.\n` +
1715+
`A Node.js worker-thread teardown bug can abort the process ` +
1716+
`when a native addon, such as fsevents, has a live Node-API ` +
1717+
`threadsafe function as a worker exits.\n` +
1718+
`See https://github.com/nodejs/node/issues/65100.`
1719+
)
1720+
} else {
1721+
Log.warn(
1722+
`\`experimental.turbopackPluginRuntimeStrategy = ` +
1723+
`'workerThreads'\` is disabled on Node.js ${nodeVersion}.\n` +
1724+
`A Node.js worker-thread teardown bug can abort the process ` +
1725+
`when a native addon, such as fsevents, has a live Node-API ` +
1726+
`threadsafe function as a worker exits.\n` +
1727+
`See https://github.com/nodejs/node/issues/65100.\n` +
1728+
`Falling back to 'childProcesses'. To override at your own ` +
1729+
`risk, use 'forceWorkerThreads'.`
1730+
)
1731+
result.experimental.turbopackPluginRuntimeStrategy = 'childProcesses'
1732+
}
1733+
}
1734+
}
1735+
}
1736+
16931737
// Store the distDirRoot in the config before it is modified for development mode
16941738
;(result as NextConfigComplete).distDirRoot = result.distDir
16951739

0 commit comments

Comments
 (0)