Skip to content

Commit a372b3c

Browse files
authored
Remove process exit signal handler (#1275)
# why `process.exit()` calls and signal handlers in BaseCache.ts were causing immediate process termination, interfering with applications' graceful shutdown logic that waits for active jobs to complete. # what changed - Removed SIGINT/SIGTERM handlers from BaseCache.ts - Removed `process.exit()` calls from BaseCache.ts and lib/index.ts - Kept passive 'exit' event handler for lock cleanup # test plan
1 parent 4994eab commit a372b3c

File tree

4 files changed

+16
-29
lines changed

4 files changed

+16
-29
lines changed

.changeset/cuddly-ears-report.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@browserbasehq/stagehand": patch
3+
---
4+
5+
Remove process exit on signal handler

evals/deterministic/tests/browserbase/sessions.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ test.describe("Browserbase Sessions", () => {
2323
});
2424
await bigStagehand.init();
2525
await bigStagehand.page.goto(
26-
"https://docs.stagehand.dev/first-steps/introduction",
26+
"https://docs.stagehand.dev/v3/first-steps/introduction",
2727
);
2828
sessionId = bigStagehand.browserbaseSessionID;
2929
if (!sessionId) {
@@ -45,7 +45,7 @@ test.describe("Browserbase Sessions", () => {
4545
const page = stagehand.page;
4646

4747
expect(page.url()).toBe(
48-
"https://docs.stagehand.dev/first-steps/introduction",
48+
"https://docs.stagehand.dev/v3/first-steps/introduction",
4949
);
5050
});
5151
test("resumes a session via CDP URL", async () => {
@@ -63,7 +63,7 @@ test.describe("Browserbase Sessions", () => {
6363
const page = stagehand.page;
6464

6565
expect(page.url()).toBe(
66-
"https://docs.stagehand.dev/first-steps/introduction",
66+
"https://docs.stagehand.dev/v3/first-steps/introduction",
6767
);
6868
});
6969
});

lib/cache/BaseCache.ts

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -43,34 +43,17 @@ export class BaseCache<T extends CacheEntry> {
4343
}
4444

4545
private setupProcessHandlers(): void {
46-
const releaseLockAndExit = () => {
46+
const releaseLockOnExit = () => {
4747
this.releaseLock();
48-
process.exit();
4948
};
5049

51-
process.on("exit", releaseLockAndExit);
52-
process.on("SIGINT", releaseLockAndExit);
53-
process.on("SIGTERM", releaseLockAndExit);
54-
process.on("uncaughtException", (err) => {
55-
this.logger({
56-
category: "base_cache",
57-
message: "uncaught exception",
58-
level: 2,
59-
auxiliary: {
60-
error: {
61-
value: err.message,
62-
type: "string",
63-
},
64-
trace: {
65-
value: err.stack,
66-
type: "string",
67-
},
68-
},
69-
});
70-
if (this.lockAcquired) {
71-
releaseLockAndExit();
72-
}
73-
});
50+
// Passive cleanup on exit - doesn't interfere with signal handling
51+
process.on("exit", releaseLockOnExit);
52+
53+
// Note: We intentionally do NOT handle SIGINT/SIGTERM here.
54+
// Applications using Stagehand as a library should manage their own
55+
// signal handlers for graceful shutdown, and call cleanup methods
56+
// (like releaseLock or a future dispose() method) explicitly.
7457
}
7558

7659
protected ensureCacheDirectory(): void {

lib/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,6 @@ export class Stagehand {
698698
});
699699
} finally {
700700
// Exit explicitly once cleanup is done
701-
process.exit(0);
702701
}
703702
};
704703

0 commit comments

Comments
 (0)