GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(server): closing a terminal also stops its background jobs (#34444) · HNRow/r3code@a7f26d2

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • apps/server/src/terminal
    • Manager.test.ts
    • Manager.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎apps/server/src/terminal/Manager.test.ts‎

Copy file name to clipboardExpand all lines: apps/server/src/terminal/Manager.test.ts
+27-1Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -993,6 +993,29 @@ it.layer(
993993
}),
994994
);
995995

996+
it.effect.each([
997+
["linux", ["SIGHUP", "SIGTERM"]],
998+
["win32", ["SIGTERM"]],
999+
] as const)("closing a %s terminal hangs up the shell's jobs", ([platform, signals]) =>
1000+
Effect.gen(function* () {
1001+
const { manager, ptyAdapter } = yield* createManager(5).pipe(
1002+
Effect.provide(layerWithHostPlatform(platform)),
1003+
);
1004+
yield* manager.open(openInput());
1005+
const shell = ptyAdapter.processes[0]!;
1006+
const terminated = yield* Deferred.make<void>();
1007+
shell.onKill = (signal) => {
1008+
if (signal === "SIGTERM") Deferred.doneUnsafe(terminated, Effect.void);
1009+
};
1010+
1011+
yield* manager.close({ threadId: "thread-1" });
1012+
yield* Deferred.await(terminated);
1013+
1014+
expect(shell.killSignals).toEqual(signals);
1015+
shell.emitExit({ exitCode: 0, signal: 0 });
1016+
}).pipe(Effect.provide(TestClock.layer())),
1017+
);
1018+
9961019
it.effect("keeps a terminal whose shell was replaced by exec open on settlement", () =>
9971020
Effect.gen(function* () {
9981021
const { manager, ptyAdapter } = yield* createManager(5, {
@@ -2790,7 +2813,10 @@ it.layer(
27902813
yield* TestClock.adjust("1 second");
27912814
yield* Fiber.join(shutdown);
27922815

2793-
expect(process.killSignals).toEqual(["SIGTERM", "SIGKILL"]);
2816+
const platform = yield* HostProcess.Platform;
2817+
expect(process.killSignals).toEqual(
2818+
platform === "win32" ? ["SIGTERM", "SIGKILL"] : ["SIGHUP", "SIGTERM", "SIGKILL"],
2819+
);
27942820
expect(process.exitListenerCount).toBe(0);
27952821
}).pipe(Effect.provide(TestClock.layer())),
27962822
);
Collapse file

‎apps/server/src/terminal/Manager.ts‎

Copy file name to clipboardExpand all lines: apps/server/src/terminal/Manager.ts
+11Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2166,6 +2166,17 @@ export const makeWithOptions = Effect.fn("TerminalManager.makeWithOptions")(func
21662166
Deferred.doneUnsafe(exited, Effect.void);
21672167
});
21682168
yield* Effect.gen(function* () {
2169+
// Interactive shells ignore SIGTERM but pass SIGHUP to their background jobs, skipping nohup'd and disowned ones.
2170+
// Windows ignores the signal and node-pty kills the whole tree there.
2171+
if (platform !== "win32") {
2172+
yield* Effect.sync(() => {
2173+
try {
2174+
process.kill("SIGHUP");
2175+
} catch {
2176+
// The SIGTERM below reports a shell that can no longer be signalled.
2177+
}
2178+
});
2179+
}
21692180
const terminated = yield* Effect.try({
21702181
try: () => process.kill("SIGTERM"),
21712182
catch: (cause) =>

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.