Only allow a maximum of 2 seconds to persist terminal sessions

Almost all cases will resolve well before 2 seconds, this is just to catch
the edge cases where the remote connection is very high latency or the remote
side is reconnecting.

Fixes #137468
This commit is contained in:
Daniel Imms 2021-11-22 14:50:34 -08:00
parent 955fc38aed
commit d15c58eb20
2 changed files with 10 additions and 2 deletions

View file

@ -504,7 +504,15 @@ export class TerminalService implements ITerminalService {
this._shutdownWindowCount = await this._nativeDelegate?.getWindowCount();
const shouldReviveProcesses = this._shouldReviveProcesses(reason);
if (shouldReviveProcesses) {
await this._primaryBackend?.persistTerminalState();
// Attempt to persist the terminal state but only allow 2000ms as we can't block
// shutdown. This can happen when in a remote workspace but the other side has been
// suspended and is in the process of reconnecting, the message will be put in a
// queue in this case for when the connection is back up and running. Aborting the
// process is preferable in this case.
await Promise.race([
this._primaryBackend?.persistTerminalState(),
timeout(2000)
]);
}
// Persist terminal _processes_

View file

@ -489,7 +489,7 @@ const terminalConfiguration: IConfigurationNode = {
default: true
},
[TerminalSettingId.PersistentSessionReviveProcess]: {
description: localize('terminal.integrated.persistentSessionReviveProcess', "When the terminal process must be shutdown (eg. on window or application close), this determines when the previous terminal session contents should be restored and processes be recreated when the workspace is next opened. Restoring of the process current working directory depends on whether it is supported by the shell."),
markdownDescription: localize('terminal.integrated.persistentSessionReviveProcess', "When the terminal process must be shutdown (eg. on window or application close), this determines when the previous terminal session contents should be restored and processes be recreated when the workspace is next opened.\n\nCaveats:\n\n- Restoring of the process current working directory depends on whether it is supported by the shell.\n- Time to persist the session during shutdown is limited, so it may be aborted when using high-latency remote connections."),
type: 'string',
enum: ['onExit', 'onExitAndWindowClose', 'never'],
markdownEnumDescriptions: [