Skip to content

Commit 82f198f

Browse files
author
Deploy Bot
committed
Merge remote-tracking branch 'remotes/origin/fix/sentry-oom-2920'
2 parents 8c986db + ed41f0a commit 82f198f

File tree

7 files changed

+117
-53
lines changed

7 files changed

+117
-53
lines changed

.changeset/fix-sentry-oom-2920.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@trigger.dev/cli-v3": patch
3+
---
4+
5+
Fix Sentry OOM: Allow disabling `source-map-support` via `TRIGGER_SOURCE_MAPS=false`. Also supports `node` for native source maps. (#2920)

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,14 @@ 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";
16+
import { installSourceMapSupport } from "../utilities/sourceMaps.js";
1717
import { registerResources } from "../indexing/registerResources.js";
1818
import { env } from "std-env";
1919
import { normalizeImportPath } from "../utilities/normalizeImportPath.js";
2020
import { detectRuntimeVersion } from "@trigger.dev/core/v3/build";
2121
import { schemaToJsonSchema } from "@trigger.dev/schema-to-json";
2222

23-
sourceMapSupport.install({
24-
handleUncaughtExceptions: false,
25-
environment: "node",
26-
hookRequire: false,
27-
});
23+
installSourceMapSupport();
2824

2925
process.on("uncaughtException", function (error, origin) {
3026
if (error instanceof Error) {

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

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -63,17 +63,9 @@ 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";
67-
import { env } from "std-env";
68-
import { normalizeImportPath } from "../utilities/normalizeImportPath.js";
69-
import { VERSION } from "../version.js";
70-
import { promiseWithResolvers } from "@trigger.dev/core/utils";
71-
72-
sourceMapSupport.install({
73-
handleUncaughtExceptions: false,
74-
environment: "node",
75-
hookRequire: false,
76-
});
66+
import { installSourceMapSupport } from "../utilities/sourceMaps.js";
67+
68+
installSourceMapSupport();
7769

7870
process.on("uncaughtException", function (error, origin) {
7971
logError("Uncaught exception", { error, origin });
@@ -109,9 +101,8 @@ process.on("uncaughtException", function (error, origin) {
109101
}
110102
});
111103

112-
process.title = `trigger-dev-run-worker (${
113-
getEnvVar("TRIGGER_WORKER_VERSION") ?? "unknown version"
114-
})`;
104+
process.title = `trigger-dev-run-worker (${getEnvVar("TRIGGER_WORKER_VERSION") ?? "unknown version"
105+
})`;
115106

116107
const heartbeatIntervalMs = getEnvVar("HEARTBEAT_INTERVAL_MS");
117108

@@ -156,7 +147,7 @@ const standardRealtimeStreamsManager = new StandardRealtimeStreamsManager(
156147
apiClientManager.clientOrThrow(),
157148
getEnvVar("TRIGGER_STREAM_URL", getEnvVar("TRIGGER_API_URL")) ?? "https://api.trigger.dev",
158149
(getEnvVar("TRIGGER_STREAMS_DEBUG") === "1" || getEnvVar("TRIGGER_STREAMS_DEBUG") === "true") ??
159-
false
150+
false
160151
);
161152
realtimeStreams.setGlobalManager(standardRealtimeStreamsManager);
162153

@@ -285,12 +276,12 @@ async function doBootstrap() {
285276

286277
let bootstrapCache:
287278
| {
288-
tracer: TriggerTracer;
289-
tracingSDK: TracingSDK;
290-
consoleInterceptor: ConsoleInterceptor;
291-
config: TriggerConfig;
292-
workerManifest: WorkerManifest;
293-
}
279+
tracer: TriggerTracer;
280+
tracingSDK: TracingSDK;
281+
consoleInterceptor: ConsoleInterceptor;
282+
config: TriggerConfig;
283+
workerManifest: WorkerManifest;
284+
}
294285
| undefined;
295286

296287
async function bootstrap() {

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

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,14 @@ 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";
16+
import { installSourceMapSupport } from "../utilities/sourceMaps.js";
1717
import { registerResources } from "../indexing/registerResources.js";
1818
import { env } from "std-env";
1919
import { normalizeImportPath } from "../utilities/normalizeImportPath.js";
2020
import { detectRuntimeVersion } from "@trigger.dev/core/v3/build";
2121
import { schemaToJsonSchema } from "@trigger.dev/schema-to-json";
2222

23-
sourceMapSupport.install({
24-
handleUncaughtExceptions: false,
25-
environment: "node",
26-
hookRequire: false,
27-
});
23+
installSourceMapSupport();
2824

2925
process.on("uncaughtException", function (error, origin) {
3026
if (error instanceof Error) {
@@ -168,8 +164,8 @@ await sendMessageInCatalog(
168164
typeof processKeepAlive === "object"
169165
? processKeepAlive
170166
: typeof processKeepAlive === "boolean"
171-
? { enabled: processKeepAlive }
172-
: undefined,
167+
? { enabled: processKeepAlive }
168+
: undefined,
173169
timings,
174170
},
175171
importErrors,

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

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -63,17 +63,9 @@ 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";
67-
import { env } from "std-env";
68-
import { normalizeImportPath } from "../utilities/normalizeImportPath.js";
69-
import { VERSION } from "../version.js";
70-
import { promiseWithResolvers } from "@trigger.dev/core/utils";
71-
72-
sourceMapSupport.install({
73-
handleUncaughtExceptions: false,
74-
environment: "node",
75-
hookRequire: false,
76-
});
66+
import { installSourceMapSupport } from "../utilities/sourceMaps.js";
67+
68+
installSourceMapSupport();
7769

7870
process.on("uncaughtException", function (error, origin) {
7971
console.error("Uncaught exception", { error, origin });
@@ -136,7 +128,7 @@ const standardRealtimeStreamsManager = new StandardRealtimeStreamsManager(
136128
apiClientManager.clientOrThrow(),
137129
getEnvVar("TRIGGER_STREAM_URL", getEnvVar("TRIGGER_API_URL")) ?? "https://api.trigger.dev",
138130
(getEnvVar("TRIGGER_STREAMS_DEBUG") === "1" || getEnvVar("TRIGGER_STREAMS_DEBUG") === "true") ??
139-
false
131+
false
140132
);
141133
realtimeStreams.setGlobalManager(standardRealtimeStreamsManager);
142134

@@ -262,12 +254,12 @@ async function doBootstrap() {
262254

263255
let bootstrapCache:
264256
| {
265-
tracer: TriggerTracer;
266-
tracingSDK: TracingSDK;
267-
consoleInterceptor: ConsoleInterceptor;
268-
config: TriggerConfig;
269-
workerManifest: WorkerManifest;
270-
}
257+
tracer: TriggerTracer;
258+
tracingSDK: TracingSDK;
259+
consoleInterceptor: ConsoleInterceptor;
260+
config: TriggerConfig;
261+
workerManifest: WorkerManifest;
262+
}
271263
| undefined;
272264

273265
async function bootstrap() {
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
2+
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
3+
import sourceMapSupport from "source-map-support";
4+
import { installSourceMapSupport } from "./sourceMaps.js";
5+
6+
vi.mock("source-map-support", () => ({
7+
default: {
8+
install: vi.fn(),
9+
},
10+
}));
11+
12+
describe("installSourceMapSupport", () => {
13+
const originalEnv = process.env;
14+
const originalSetSourceMapsEnabled = process.setSourceMapsEnabled;
15+
16+
beforeEach(() => {
17+
vi.clearAllMocks();
18+
process.env = { ...originalEnv };
19+
// Mock setSourceMapsEnabled if it doesn't exist (Node < 16.6) or restore it
20+
process.setSourceMapsEnabled = vi.fn();
21+
});
22+
23+
afterEach(() => {
24+
process.env = originalEnv;
25+
process.setSourceMapsEnabled = originalSetSourceMapsEnabled;
26+
});
27+
28+
it("should install source-map-support by default (undefined env var)", () => {
29+
delete process.env.TRIGGER_SOURCE_MAPS;
30+
installSourceMapSupport();
31+
expect(sourceMapSupport.install).toHaveBeenCalledWith({
32+
handleUncaughtExceptions: false,
33+
environment: "node",
34+
hookRequire: false,
35+
});
36+
});
37+
38+
it("should install source-map-support if env var is 'true'", () => {
39+
process.env.TRIGGER_SOURCE_MAPS = "true";
40+
installSourceMapSupport();
41+
expect(sourceMapSupport.install).toHaveBeenCalled();
42+
});
43+
44+
it("should NOT install source-map-support if env var is 'false'", () => {
45+
process.env.TRIGGER_SOURCE_MAPS = "false";
46+
installSourceMapSupport();
47+
expect(sourceMapSupport.install).not.toHaveBeenCalled();
48+
});
49+
50+
it("should NOT install source-map-support if env var is '0'", () => {
51+
process.env.TRIGGER_SOURCE_MAPS = "0";
52+
installSourceMapSupport();
53+
expect(sourceMapSupport.install).not.toHaveBeenCalled();
54+
});
55+
56+
it("should enable native node source maps if env var is 'node'", () => {
57+
process.env.TRIGGER_SOURCE_MAPS = "node";
58+
installSourceMapSupport();
59+
expect(sourceMapSupport.install).not.toHaveBeenCalled();
60+
expect(process.setSourceMapsEnabled).toHaveBeenCalledWith(true);
61+
});
62+
});
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import sourceMapSupport from "source-map-support";
2+
3+
export function installSourceMapSupport() {
4+
const sourceMaps = process.env.TRIGGER_SOURCE_MAPS;
5+
6+
if (sourceMaps === "false" || sourceMaps === "0") {
7+
return;
8+
}
9+
10+
if (sourceMaps === "node") {
11+
if (process.setSourceMapsEnabled) {
12+
process.setSourceMapsEnabled(true);
13+
}
14+
return;
15+
}
16+
17+
sourceMapSupport.install({
18+
handleUncaughtExceptions: false,
19+
environment: "node",
20+
hookRequire: false,
21+
});
22+
}

0 commit comments

Comments
 (0)