Skip to content

Commit 15091dc

Browse files
committed
fix: defer source-map-support loading to prevent OOM with Sentry debug injection
1 parent 23ec5ff commit 15091dc

File tree

5 files changed

+97
-24
lines changed

5 files changed

+97
-24
lines changed

packages/cli-v3/src/entryPoints/dev-index-worker.ts

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,29 @@ import {
1313
} from "@trigger.dev/core/v3/workers";
1414
import { sendMessageInCatalog, ZodSchemaParsedError } from "@trigger.dev/core/v3/zodMessageHandler";
1515
import { readFile } from "node:fs/promises";
16-
import sourceMapSupport from "source-map-support";
1716
import { registerResources } from "../indexing/registerResources.js";
1817
import { env } from "std-env";
1918
import { normalizeImportPath } from "../utilities/normalizeImportPath.js";
2019
import { detectRuntimeVersion } from "@trigger.dev/core/v3/build";
2120
import { schemaToJsonSchema } from "@trigger.dev/schema-to-json";
2221

23-
sourceMapSupport.install({
24-
handleUncaughtExceptions: false,
25-
environment: "node",
26-
hookRequire: false,
27-
});
22+
let sourceMapSupportInstalled = false;
23+
24+
async function installSourceMapSupport() {
25+
if (sourceMapSupportInstalled) return;
26+
sourceMapSupportInstalled = true;
27+
28+
try {
29+
const sourceMapSupport = await import("source-map-support");
30+
sourceMapSupport.default.install({
31+
handleUncaughtExceptions: false,
32+
environment: "node",
33+
hookRequire: false,
34+
});
35+
} catch (error) {
36+
console.warn("Failed to install source-map-support:", error);
37+
}
38+
}
2839

2940
process.on("uncaughtException", function (error, origin) {
3041
if (error instanceof Error) {
@@ -80,6 +91,11 @@ async function bootstrap() {
8091

8192
const { config } = await importConfig(buildManifest.configPath);
8293

94+
// Install source-map-support after config is loaded (deferred to avoid OOM with Sentry debug ID injection)
95+
if (config.sourceMapSupport !== false) {
96+
installSourceMapSupport();
97+
}
98+
8399
// This needs to run or the PrismaInstrumentation will throw an error
84100
const tracingSDK = new TracingSDK({
85101
url: env.OTEL_EXPORTER_OTLP_ENDPOINT ?? "http://0.0.0.0:4318",

packages/cli-v3/src/entryPoints/dev-run-worker.ts

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,17 +63,28 @@ import {
6363
import { ZodIpcConnection } from "@trigger.dev/core/v3/zodIpc";
6464
import { readFile } from "node:fs/promises";
6565
import { setInterval, setTimeout } from "node:timers/promises";
66-
import sourceMapSupport from "source-map-support";
6766
import { env } from "std-env";
6867
import { normalizeImportPath } from "../utilities/normalizeImportPath.js";
6968
import { VERSION } from "../version.js";
7069
import { promiseWithResolvers } from "@trigger.dev/core/utils";
7170

72-
sourceMapSupport.install({
73-
handleUncaughtExceptions: false,
74-
environment: "node",
75-
hookRequire: false,
76-
});
71+
let sourceMapSupportInstalled = false;
72+
73+
async function installSourceMapSupport() {
74+
if (sourceMapSupportInstalled) return;
75+
sourceMapSupportInstalled = true;
76+
77+
try {
78+
const sourceMapSupport = await import("source-map-support");
79+
sourceMapSupport.default.install({
80+
handleUncaughtExceptions: false,
81+
environment: "node",
82+
hookRequire: false,
83+
});
84+
} catch (error) {
85+
console.warn("Failed to install source-map-support:", error);
86+
}
87+
}
7788

7889
process.on("uncaughtException", function (error, origin) {
7990
logError("Uncaught exception", { error, origin });
@@ -271,6 +282,11 @@ async function doBootstrap() {
271282
});
272283
}
273284

285+
// Install source-map-support after config is loaded (deferred to avoid OOM with Sentry debug ID injection)
286+
if (config.sourceMapSupport !== false) {
287+
installSourceMapSupport();
288+
}
289+
274290
log("Bootstrapped worker");
275291

276292
return {

packages/cli-v3/src/entryPoints/managed-index-worker.ts

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,29 @@ import {
1313
} from "@trigger.dev/core/v3/workers";
1414
import { sendMessageInCatalog, ZodSchemaParsedError } from "@trigger.dev/core/v3/zodMessageHandler";
1515
import { readFile } from "node:fs/promises";
16-
import sourceMapSupport from "source-map-support";
1716
import { registerResources } from "../indexing/registerResources.js";
1817
import { env } from "std-env";
1918
import { normalizeImportPath } from "../utilities/normalizeImportPath.js";
2019
import { detectRuntimeVersion } from "@trigger.dev/core/v3/build";
2120
import { schemaToJsonSchema } from "@trigger.dev/schema-to-json";
2221

23-
sourceMapSupport.install({
24-
handleUncaughtExceptions: false,
25-
environment: "node",
26-
hookRequire: false,
27-
});
22+
let sourceMapSupportInstalled = false;
23+
24+
async function installSourceMapSupport() {
25+
if (sourceMapSupportInstalled) return;
26+
sourceMapSupportInstalled = true;
27+
28+
try {
29+
const sourceMapSupport = await import("source-map-support");
30+
sourceMapSupport.default.install({
31+
handleUncaughtExceptions: false,
32+
environment: "node",
33+
hookRequire: false,
34+
});
35+
} catch (error) {
36+
console.warn("Failed to install source-map-support:", error);
37+
}
38+
}
2839

2940
process.on("uncaughtException", function (error, origin) {
3041
if (error instanceof Error) {
@@ -80,6 +91,11 @@ async function bootstrap() {
8091

8192
const { config } = await importConfig(buildManifest.configPath);
8293

94+
// Install source-map-support after config is loaded (deferred to avoid OOM with Sentry debug ID injection)
95+
if (config.sourceMapSupport !== false) {
96+
installSourceMapSupport();
97+
}
98+
8399
// This needs to run or the PrismaInstrumentation will throw an error
84100
const tracingSDK = new TracingSDK({
85101
url: env.OTEL_EXPORTER_OTLP_ENDPOINT ?? "http://0.0.0.0:4318",

packages/cli-v3/src/entryPoints/managed-run-worker.ts

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,17 +63,28 @@ import {
6363
import { ZodIpcConnection } from "@trigger.dev/core/v3/zodIpc";
6464
import { readFile } from "node:fs/promises";
6565
import { setInterval, setTimeout } from "node:timers/promises";
66-
import sourceMapSupport from "source-map-support";
6766
import { env } from "std-env";
6867
import { normalizeImportPath } from "../utilities/normalizeImportPath.js";
6968
import { VERSION } from "../version.js";
7069
import { promiseWithResolvers } from "@trigger.dev/core/utils";
7170

72-
sourceMapSupport.install({
73-
handleUncaughtExceptions: false,
74-
environment: "node",
75-
hookRequire: false,
76-
});
71+
let sourceMapSupportInstalled = false;
72+
73+
async function installSourceMapSupport() {
74+
if (sourceMapSupportInstalled) return;
75+
sourceMapSupportInstalled = true;
76+
77+
try {
78+
const sourceMapSupport = await import("source-map-support");
79+
sourceMapSupport.default.install({
80+
handleUncaughtExceptions: false,
81+
environment: "node",
82+
hookRequire: false,
83+
});
84+
} catch (error) {
85+
console.warn("Failed to install source-map-support:", error);
86+
}
87+
}
7788

7889
process.on("uncaughtException", function (error, origin) {
7990
console.error("Uncaught exception", { error, origin });
@@ -250,6 +261,11 @@ async function doBootstrap() {
250261
});
251262
}
252263

264+
// Install source-map-support after config is loaded (deferred to avoid OOM with Sentry debug ID injection)
265+
if (config.sourceMapSupport !== false) {
266+
installSourceMapSupport();
267+
}
268+
253269
return {
254270
tracer,
255271
tracingSDK,

packages/core/src/v3/config.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,15 @@ export type TriggerConfig = {
171171
*/
172172
disableConsoleInterceptor?: boolean;
173173

174+
/**
175+
* Enable or disable source-map-support for enhanced stack traces.
176+
* Disabling this can help prevent OOM issues when using Sentry's debug ID injection
177+
* with large projects that have many bundled files.
178+
*
179+
* @default true
180+
*/
181+
sourceMapSupport?: boolean;
182+
174183
build?: {
175184
/**
176185
* Add custom conditions to the esbuild build. For example, if you are importing `ai/rsc`, you'll need to add "react-server" condition.

0 commit comments

Comments
 (0)