Skip to content

Use span instead of Electron.relaunch to avoid restrictions in the new process#296711

Draft
dmitrivMS wants to merge 1 commit intomainfrom
dev/dmitriv/linux-relaunch-fix
Draft

Use span instead of Electron.relaunch to avoid restrictions in the new process#296711
dmitrivMS wants to merge 1 commit intomainfrom
dev/dmitriv/linux-relaunch-fix

Conversation

@dmitrivMS
Copy link
Copy Markdown
Contributor

Fixes #253204

@dmitrivMS dmitrivMS added this to the February 2026 milestone Feb 21, 2026
@dmitrivMS dmitrivMS self-assigned this Feb 21, 2026
@dmitrivMS dmitrivMS added install-update VS Code installation and upgrade system issues linux Issues with VS Code on Linux labels Feb 21, 2026
Copilot AI review requested due to automatic review settings February 21, 2026 09:35
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates the Electron main-process relaunch flow to avoid Electron’s app.relaunch() behavior on Linux that results in relaunched VS Code instances inheriting PR_SET_NO_NEW_PRIVS (breaking sudo in integrated terminals), matching the behavior of a normal OS-level launch.

Changes:

  • Use child_process.spawn(process.execPath, args, …) for relaunch on Linux instead of electron.app.relaunch({ args }).
  • Keep electron.app.relaunch() for macOS/Windows relaunch behavior unchanged.
  • Add Linux-specific tracing and inline rationale referencing issue #253204.

// sudo from working in VS Code terminals (https://github.com/microsoft/vscode/issues/253204).
// Spawn the new process via Node.js which does not set this flag.
this.trace('Lifecycle#relaunch() - calling spawn()');
const child = spawn(process.execPath, args, { detached: true, stdio: 'ignore' });
Copy link

Copilot AI Feb 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spawn() can emit an 'error' event (e.g. ENOENT if process.execPath is temporarily unavailable during an upgrade). Without an error listener, that becomes an unhandled 'error' event and can crash the process during quit. Consider adding a child.on('error', …) handler to log the failure and (optionally) fall back to electron.app.relaunch({ args }) or otherwise prevent an unhandled exception.

Suggested change
const child = spawn(process.execPath, args, { detached: true, stdio: 'ignore' });
const child = spawn(process.execPath, args, { detached: true, stdio: 'ignore' });
child.on('error', error => {
this.logService.error('[Lifecycle#relaunch] Failed to spawn new process', error);
this.trace('Lifecycle#relaunch() - spawn() failed, falling back to app.relaunch()');
try {
electron.app.relaunch({ args });
} catch (fallbackError) {
this.logService.error('[Lifecycle#relaunch] Failed to relaunch app after spawn error', fallbackError);
}
});

Copilot uses AI. Check for mistakes.
electron.app.relaunch({ args });
if (isLinux) {
// On Linux, Electron's app.relaunch() uses Chromium's base::LaunchProcess()
// which sets PR_SET_NO_NEW_PRIVS on the new process by default, preventing
Copy link
Copy Markdown
Collaborator

@deepak1556 deepak1556 Feb 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not true, the relaunched program is allowed privileges https://github.com/electron/electron/blob/aca83afeef7cdebce10c6fa9835baed26c806b9f/shell/browser/relauncher_linux.cc#L63

So what needs checking is,

  1. The relaunch path will shutdown the current app gracefully and relaunch self executable with a special commandline that will cause a different main function to be invoked https://github.com/electron/electron/blob/aca83afeef7cdebce10c6fa9835baed26c806b9f/shell/browser/relauncher.cc#L117 options.allow_new_privs = false in here
  2. This new main function https://github.com/electron/electron/blob/aca83afeef7cdebce10c6fa9835baed26c806b9f/shell/browser/relauncher.cc#L160 will then proceed to launch the executable with provided arguments options.allow_new_privs = true here

If the final application process is still getting PR_SET_NO_NEW_PRIVS then it is very likely inherited from the relauncher process, lets confirm this and get a proper fix into the relaunch code of Electron. Relying on node.js process launch will complicate shutdown sequence which we get for free from the relaunch api.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep,' it's in draft as I haven't been able to test any of it yet.

@dmitrivMS dmitrivMS removed this from the 1.112.0 milestone Mar 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

install-update VS Code installation and upgrade system issues linux Issues with VS Code on Linux

Projects

None yet

Development

Successfully merging this pull request may close these issues.

VSCode instances started through "Relaunch VS Code" button are started with PR_SET_NO_NEW_PRIVS

3 participants