Skip to content

The agent that grows with you

fix(desktop): log the /bin/sh relaunch fallback and always exit after a relaunch attempt

Teknium5c468b3667aa
diff --git a/apps/desktop/electron/app-relaunch.ts b/apps/desktop/electron/app-relaunch.ts
index 3ecce785587..f44d437288a 100644
--- a/apps/desktop/electron/app-relaunch.ts
+++ b/apps/desktop/electron/app-relaunch.ts
@@ -66,24 +66,27 @@ export function createAppRelauncher(
exit: code => {
exiting = true
- if (pendingArgs) {
- // The new process skips `hermes desktop`: it needs the launcher's short socket TMPDIR,
- // not the long one main.ts restored after the lock (linux-sandbox-relaunch.ts).
- const childEnv = { ...env }
- restoreLaunchTmpdir(childEnv)
- const target = relaunchTarget(execPath, env)
+ try {
+ if (pendingArgs) {
+ // The new process skips `hermes desktop`: it needs the launcher's short socket TMPDIR,
+ // not the long one main.ts restored after the lock (linux-sandbox-relaunch.ts).
+ const childEnv = { ...env }
+ restoreLaunchTmpdir(childEnv)
+ const target = relaunchTarget(execPath, env)
- if (canRelaunch(target, 'relaunching through Electron instead', childEnv)) {
- relaunchNow(app, pendingArgs, target, childEnv)
- } else {
- // The backend is already down: Electron's relauncher is the last way back.
- app.relaunch({ args: pendingArgs })
- }
+ if (canRelaunch(target, 'relaunching through Electron instead', childEnv)) {
+ relaunchNow(app, pendingArgs, target, childEnv)
+ } else {
+ // The backend is already down: Electron's relauncher is the last way back.
+ app.relaunch({ args: pendingArgs })
+ }
- pendingArgs = null
+ pendingArgs = null
+ }
+ } finally {
+ // A synchronous spawn throw (E2BIG) must not leave the app running with its lock released.
+ app.exit(code)
}
-
- app.exit(code)
}
}
}
diff --git a/apps/desktop/electron/relaunch-target.ts b/apps/desktop/electron/relaunch-target.ts
index 1cc2876ff9f..4a685e1a4b4 100644
--- a/apps/desktop/electron/relaunch-target.ts
+++ b/apps/desktop/electron/relaunch-target.ts
@@ -95,12 +95,18 @@ function executableError(file: string): string | null {
* rewrites an exported SHELLOPTS/BASHOPTS for its children, so an env that
* carries one keeps /bin/sh.
*/
-function trampolineShell(env: NodeJS.ProcessEnv): { file: string; args: string[] } {
- if (env.SHELLOPTS === undefined && env.BASHOPTS === undefined && !executableError('/bin/bash')) {
+function trampolineShell(env: NodeJS.ProcessEnv): { file: string; args: string[]; fallback?: string } {
+ const bashOptsExported = env.SHELLOPTS !== undefined || env.BASHOPTS !== undefined
+
+ if (!bashOptsExported && !executableError('/bin/bash')) {
return { file: '/bin/bash', args: ['-p'] }
}
- return { file: '/bin/sh', args: [] }
+ return {
+ file: '/bin/sh',
+ args: [],
+ fallback: bashOptsExported ? 'SHELLOPTS/BASHOPTS exported' : '/bin/bash unavailable'
+ }
}
/**
@@ -227,6 +233,12 @@ export function relaunchNow(
const childEnv = ownImage ? withoutMountEntries(env, execPath) : env
const shell = trampolineShell(env)
+ if (shell.fallback) {
+ console.warn(
+ `[hermes] relaunching through /bin/sh (${shell.fallback}); file descriptors above 9 may stay open in the new process`
+ )
+ }
+
const child = spawn(shell.file, [...shell.args, '-c', EXEC_WITH_STDIO_ONLY, target, ...args], {
detached: true,
stdio: 'ignore',