The best way to control Claude Code, Codex and more from any computer or phone
fix(desktop): AppImage updates no longer leave old runtimes and mounts running (#29672)
Julius Marminge committed
Nov 11, 2026 at 16:09 UTC
98fd5f2fe2967fb54286ad402fdb3182394dfb20
2 files changed
+140
-1
apps/desktop/src/electron/ElectronUpdater.test.ts
new
+118
@@ -0,0 +1,118 @@
1
+// @effect-diagnostics nodeBuiltinImport:off -- Intercepts the spawn electron-updater requires natively.
2
+import * as NodeServices from "@effect/platform-node/NodeServices";
3
+import { assert, describe, it } from "@effect/vitest";
4
+import * as Deferred from "effect/Deferred";
5
+import * as Effect from "effect/Effect";
6
+import * as FileSystem from "effect/FileSystem";
7
+import * as Path from "effect/Path";
8
+import * as HostProcess from "@t3tools/shared/HostProcess";
9
+import { autoUpdater } from "electron-updater";
10
+import type * as NodeChildProcess from "node:child_process";
11
+import * as NodeModule from "node:module";
12
+import { vi } from "vite-plus/test";
13
+
14
+// electron-updater requires Electron natively, outside vi.mock's reach, and builds its
15
+// autoUpdater singleton as soon as it is imported.
16
+vi.hoisted(() => {
17
+ const NodeModule = process.getBuiltinModule("node:module");
18
+ const NodeEvents = process.getBuiltinModule("node:events");
19
+ const require = NodeModule.createRequire(import.meta.url);
20
+ const electronPath = NodeModule.createRequire(require.resolve("electron-updater")).resolve(
21
+ "electron",
22
+ );
23
+ const electronModule = new NodeModule.Module(electronPath);
24
+ electronModule.filename = electronPath;
25
+ electronModule.loaded = true;
26
+ electronModule.exports = {
27
+ app: {
28
+ getVersion: () => "1.0.0",
29
+ getName: () => "T3 Code",
30
+ isPackaged: true,
31
+ quit: () => undefined,
32
+ once: () => undefined,
33
+ },
34
+ autoUpdater: new NodeEvents.EventEmitter(),
35
+ };
36
+ require.cache[electronPath] = electronModule;
37
+});
38
+
39
+import * as ElectronUpdater from "./ElectronUpdater.ts";
40
+
41
+const childProcess = NodeModule.createRequire(import.meta.url)("node:child_process") as {
42
+ spawn: (
43
+ command: string,
44
+ args: ReadonlyArray<string>,
45
+ options: NodeChildProcess.SpawnOptions,
46
+ ) => NodeChildProcess.ChildProcess;
47
+};
48
+
49
+describe.skipIf(HostProcess.Platform.defaultValue() !== "linux")(
50
+ "ElectronUpdater AppImage install",
51
+ () => {
52
+ it.live("relaunches the installed AppImage without the updating process's descriptors", () =>
53
+ Effect.gen(function* () {
54
+ const fileSystem = yield* FileSystem.FileSystem;
55
+ const path = yield* Path.Path;
56
+ const dir = yield* fileSystem.makeTempDirectoryScoped({ prefix: "t3-appimage-install-" });
57
+ const appImagePath = path.join(dir, "T3-Code.AppImage");
58
+ const stagedPath = path.join(dir, "T3-Code-1.0.1.AppImage");
59
+ const fdReportPath = path.join(dir, "relaunched-fds.txt");
60
+ yield* fileSystem.writeFileString(appImagePath, "old AppImage");
61
+ yield* fileSystem.writeFileString(
62
+ stagedPath,
63
+ `#!/bin/sh\nls /proc/self/fd > '${fdReportPath}'\n`,
64
+ );
65
+ yield* fileSystem.chmod(stagedPath, 0o755);
66
+
67
+ yield* Effect.acquireRelease(
68
+ Effect.sync(() => vi.stubEnv("APPIMAGE", appImagePath)),
69
+ () => Effect.sync(() => vi.unstubAllEnvs()),
70
+ );
71
+
72
+ autoUpdater.logger = null;
73
+ Object.assign(autoUpdater, {
74
+ downloadedUpdateHelper: {
75
+ file: stagedPath,
76
+ downloadedFileInfo: { isAdminRightsRequired: false },
77
+ },
78
+ });
79
+
80
+ // Electron's main process holds the AppImage runtime's keepalive pipe and some
81
+ // Chromium files without O_CLOEXEC. Node cannot hold such a descriptor, so the
82
+ // relaunch runs with fd 7 opened that way to stand in for them.
83
+ const relaunched = yield* Deferred.make<void>();
84
+ const realSpawn = childProcess.spawn;
85
+ yield* Effect.acquireRelease(
86
+ Effect.sync(() => {
87
+ childProcess.spawn = (command, args, options) => {
88
+ const child = realSpawn(
89
+ "bash",
90
+ ["-c", 'exec 7</dev/null; exec "$@"', "leaky-parent", command, ...args],
91
+ options,
92
+ );
93
+ child.once("exit", () => Deferred.doneUnsafe(relaunched, Effect.void));
94
+ return child;
95
+ };
96
+ NodeModule.syncBuiltinESMExports();
97
+ }),
98
+ () =>
99
+ Effect.sync(() => {
100
+ childProcess.spawn = realSpawn;
101
+ NodeModule.syncBuiltinESMExports();
102
+ }),
103
+ );
104
+
105
+ const electronUpdater = yield* ElectronUpdater.ElectronUpdater;
106
+ yield* electronUpdater.quitAndInstall({ isSilent: true, isForceRunAfter: true });
107
+ yield* Deferred.await(relaunched);
108
+
109
+ const descriptors = (yield* fileSystem.readFileString(fdReportPath)).trim().split("\n");
110
+ assert.notInclude(
111
+ descriptors,
112
+ "7",
113
+ `relaunched AppImage inherited the updating process's fd 7 (open fds: ${descriptors.join(" ")})`,
114
+ );
115
+ }).pipe(Effect.provide([ElectronUpdater.layer, NodeServices.layer])),
116
+ );
117
+ },
118
+);
apps/desktop/src/electron/ElectronUpdater.ts
+22
-1
@@ -4,9 +4,29 @@ import * as Layer from "effect/Layer";
4
import * as Schema from "effect/Schema";
5
import * as Scope from "effect/Scope";
6
7
-import { autoUpdater } from "electron-updater";
7
+import { AppImageUpdater, autoUpdater } from "electron-updater";
8
9
type AutoUpdater = typeof autoUpdater;
10
+type SpawnLog = (cmd: string, args?: Array<string>, ...rest: Array<unknown>) => Promise<boolean>;
11
+
12
+// Electron holds the AppImage runtime's keepalive pipe and some files without O_CLOEXEC; a
13
+// relaunched AppImage inherits them, so old runtimes and FUSE mounts never exit. bash (AppRun
14
+// already needs it; dash cannot close multi-digit fds) closes them before exec'ing the AppImage.
15
+// -p skips BASH_ENV and exported functions in the helper only; the AppImage still receives both.
16
+const CLOSE_INHERITED_FDS_THEN_EXEC =
17
+ 'for fd in /proc/self/fd/*; do fd=${fd##*/}; case $fd in *[!0-9]*|[012]) ;; *) eval "exec $fd>&-" ;; esac; done; exec "$@"';
18
+
19
+const relaunchWithoutInheritedDescriptors = (updater: AppImageUpdater) => {
20
+ const spawnLog = (AppImageUpdater.prototype as unknown as { spawnLog: SpawnLog }).spawnLog;
21
+ (updater as unknown as { spawnLog: SpawnLog }).spawnLog = function (cmd, args = [], ...rest) {
22
+ return spawnLog.call(
23
+ this,
24
+ "bash",
25
+ ["-p", "-c", CLOSE_INHERITED_FDS_THEN_EXEC, cmd, cmd, ...args],
26
+ ...rest,
27
+ );
28
+ };
29
+};
30
31
export type ElectronUpdaterFeedUrl = Parameters<AutoUpdater["setFeedURL"]>[0];
32
@@ -153,6 +173,7 @@ export const make = ElectronUpdater.of({
173
}) {
174
return Effect.suspend(() => {
175
const channel = autoUpdater.channel;
176
+ if (autoUpdater instanceof AppImageUpdater) relaunchWithoutInheritedDescriptors(autoUpdater);
177
return Effect.try({
178
try: () => autoUpdater.quitAndInstall(isSilent, isForceRunAfter),
179
catch: (cause) =>