Fix memory leak in dev server
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
/**
|
||||
* Disposes the hydration and SSR esbuild contexts, releasing the incremental
|
||||
* build state esbuild keeps in memory for them. The bundlers re-create the
|
||||
* contexts on their next run.
|
||||
*/
|
||||
export default function disposeBundlerContexts(): Promise<void>;
|
||||
@@ -0,0 +1,17 @@
|
||||
/**
|
||||
* Disposes the hydration and SSR esbuild contexts, releasing the incremental
|
||||
* build state esbuild keeps in memory for them. The bundlers re-create the
|
||||
* contexts on their next run.
|
||||
*/
|
||||
export default async function disposeBundlerContexts() {
|
||||
try {
|
||||
await global.BUNEXT_BUNDLER_CTX?.dispose();
|
||||
}
|
||||
catch (error) { }
|
||||
global.BUNEXT_BUNDLER_CTX = undefined;
|
||||
try {
|
||||
await global.BUNEXT_SSR_BUNDLER_CTX?.dispose();
|
||||
}
|
||||
catch (error) { }
|
||||
global.BUNEXT_SSR_BUNDLER_CTX = undefined;
|
||||
}
|
||||
@@ -8,6 +8,7 @@ import grabRootFilePath from "../server/web-pages/grab-root-file-path";
|
||||
import ssrVirtualFilesPlugin from "./plugins/ssr-virtual-files-plugin";
|
||||
import ssrCTXArtifactTracker from "./plugins/ssr-ctx-artifact-tracker";
|
||||
import cleanupArtifacts from "../server/cleanup-artifacts";
|
||||
import { evictDeletedModules } from "../../utils/import-fresh";
|
||||
import { writeFileSync } from "fs";
|
||||
import path from "path";
|
||||
import { log } from "../../utils/log";
|
||||
@@ -165,6 +166,9 @@ async function doSSRRebuild(params) {
|
||||
global.BUNEXT_SSR_BUNDLER_CTX_DISPOSED = false;
|
||||
global.BUNEXT_BUILD_FAILED = false;
|
||||
await cleanupArtifacts({ paradigm: "ssr" });
|
||||
// esbuild has now replaced superseded outputs on disk; release the
|
||||
// ones the server already imported.
|
||||
evictDeletedModules(BUNX_CWD_MODULE_CACHE_DIR);
|
||||
}
|
||||
catch (error) {
|
||||
global.BUNEXT_SSR_BUNDLER_CTX_DISPOSED = true;
|
||||
|
||||
Reference in New Issue
Block a user