Unverified Commit 5da8ad7b authored by Zack Tanner's avatar Zack Tanner Committed by GitHub

move static worker IPC server behind experimental flag (#57943)

A shared incremental cache IPC server was introduced for build-time static workers as an optimization to dedupe fetch requests, however this can cause fetch-related flakiness to builds under certain conditions (e.g., large payloads).

This moves the optimization behind an experimental flag to unblock those running into IPC-related build time errors while we work on an alternative solution for the underlying issue

Fixes #53695
parent ad55d781
...@@ -1218,8 +1218,8 @@ export default async function build( ...@@ -1218,8 +1218,8 @@ export default async function build(
: config.experimental.cpus || 4 : config.experimental.cpus || 4
function createStaticWorker( function createStaticWorker(
incrementalCacheIpcPort: number, incrementalCacheIpcPort?: number,
incrementalCacheIpcValidationKey: string incrementalCacheIpcValidationKey?: string
) { ) {
let infoPrinted = false let infoPrinted = false
...@@ -1259,7 +1259,9 @@ export default async function build( ...@@ -1259,7 +1259,9 @@ export default async function build(
forkOptions: { forkOptions: {
env: { env: {
...process.env, ...process.env,
__NEXT_INCREMENTAL_CACHE_IPC_PORT: incrementalCacheIpcPort + '', __NEXT_INCREMENTAL_CACHE_IPC_PORT: incrementalCacheIpcPort
? incrementalCacheIpcPort + ''
: undefined,
__NEXT_INCREMENTAL_CACHE_IPC_KEY: __NEXT_INCREMENTAL_CACHE_IPC_KEY:
incrementalCacheIpcValidationKey, incrementalCacheIpcValidationKey,
}, },
...@@ -1281,42 +1283,45 @@ export default async function build( ...@@ -1281,42 +1283,45 @@ export default async function build(
> >
} }
let CacheHandler: any let incrementalCacheIpcPort
let incrementalCacheIpcValidationKey
if (incrementalCacheHandlerPath) { if (config.experimental.staticWorkerRequestDeduping) {
CacheHandler = require(path.isAbsolute(incrementalCacheHandlerPath) let CacheHandler
? incrementalCacheHandlerPath if (incrementalCacheHandlerPath) {
: path.join(dir, incrementalCacheHandlerPath)) CacheHandler = require(path.isAbsolute(incrementalCacheHandlerPath)
CacheHandler = CacheHandler.default || CacheHandler ? incrementalCacheHandlerPath
} : path.join(dir, incrementalCacheHandlerPath))
CacheHandler = CacheHandler.default || CacheHandler
}
const { const cacheInitialization = await initializeIncrementalCache({
ipcPort: incrementalCacheIpcPort, fs: nodeFs,
ipcValidationKey: incrementalCacheIpcValidationKey, dev: false,
} = await initializeIncrementalCache({ pagesDir: true,
fs: nodeFs, appDir: true,
dev: false, fetchCache: true,
pagesDir: true, flushToDisk: config.experimental.isrFlushToDisk,
appDir: true, serverDistDir: path.join(distDir, 'server'),
fetchCache: true, fetchCacheKeyPrefix: config.experimental.fetchCacheKeyPrefix,
flushToDisk: config.experimental.isrFlushToDisk, maxMemoryCacheSize: config.experimental.isrMemoryCacheSize,
serverDistDir: path.join(distDir, 'server'), getPrerenderManifest: () => ({
fetchCacheKeyPrefix: config.experimental.fetchCacheKeyPrefix, version: -1 as any, // letting us know this doesn't conform to spec
maxMemoryCacheSize: config.experimental.isrMemoryCacheSize, routes: {},
getPrerenderManifest: () => ({ dynamicRoutes: {},
version: -1 as any, // letting us know this doesn't conform to spec notFoundRoutes: [],
routes: {}, preview: null as any, // `preview` is special case read in next-dev-server
dynamicRoutes: {}, }),
notFoundRoutes: [], requestHeaders: {},
preview: null as any, // `preview` is special case read in next-dev-server CurCacheHandler: CacheHandler,
}), minimalMode: ciEnvironment.hasNextSupport,
requestHeaders: {}, allowedRevalidateHeaderKeys:
CurCacheHandler: CacheHandler, config.experimental.allowedRevalidateHeaderKeys,
minimalMode: ciEnvironment.hasNextSupport, })
allowedRevalidateHeaderKeys: incrementalCacheIpcPort = cacheInitialization.ipcPort
config.experimental.allowedRevalidateHeaderKeys, incrementalCacheIpcValidationKey = cacheInitialization.ipcValidationKey
}) }
const pagesStaticWorkers = createStaticWorker( const pagesStaticWorkers = createStaticWorker(
incrementalCacheIpcPort, incrementalCacheIpcPort,
......
...@@ -366,6 +366,7 @@ export const configSchema: zod.ZodType<NextConfig> = z.lazy(() => ...@@ -366,6 +366,7 @@ export const configSchema: zod.ZodType<NextConfig> = z.lazy(() =>
serverMinification: z.boolean().optional(), serverMinification: z.boolean().optional(),
serverSourceMaps: z.boolean().optional(), serverSourceMaps: z.boolean().optional(),
bundlePagesExternals: z.boolean().optional(), bundlePagesExternals: z.boolean().optional(),
staticWorkerRequestDeduping: z.boolean().optional(),
}) })
.optional(), .optional(),
exportPathMap: z exportPathMap: z
......
...@@ -334,6 +334,10 @@ export interface ExperimentalConfig { ...@@ -334,6 +334,10 @@ export interface ExperimentalConfig {
* Enables the bundling of node_modules packages (externals) for pages server-side bundles. * Enables the bundling of node_modules packages (externals) for pages server-side bundles.
*/ */
bundlePagesExternals?: boolean bundlePagesExternals?: boolean
/**
* Uses an IPC server to dedupe build-time requests to the cache handler
*/
staticWorkerRequestDeduping?: boolean
} }
export type ExportPathMap = { export type ExportPathMap = {
...@@ -783,6 +787,7 @@ export const defaultConfig: NextConfig = { ...@@ -783,6 +787,7 @@ export const defaultConfig: NextConfig = {
typedRoutes: false, typedRoutes: false,
instrumentationHook: false, instrumentationHook: false,
bundlePagesExternals: false, bundlePagesExternals: false,
staticWorkerRequestDeduping: false,
}, },
} }
......
...@@ -34,10 +34,15 @@ describe('app-fetch-deduping', () => { ...@@ -34,10 +34,15 @@ describe('app-fetch-deduping', () => {
afterAll(() => externalServer.close()) afterAll(() => externalServer.close())
it('dedupes requests amongst static workers', async () => { it('dedupes requests amongst static workers when experimental.staticWorkerRequestDeduping is enabled', async () => {
const next = await createNext({ const next = await createNext({
files: new FileRef(__dirname), files: new FileRef(__dirname),
env: { TEST_SERVER_PORT: `${externalServerPort}` }, env: { TEST_SERVER_PORT: `${externalServerPort}` },
nextConfig: {
experimental: {
staticWorkerRequestDeduping: true,
},
},
}) })
expect(requests.length).toBe(1) expect(requests.length).toBe(1)
......
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