From a6f884000995b85cdbec3e857eae893fd59b67b5 Mon Sep 17 00:00:00 2001 From: Asher Date: Thu, 19 Nov 2020 11:21:15 -0600 Subject: [PATCH] Add timeout for disposing detached terminals --- ci/dev/vscode.patch | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/ci/dev/vscode.patch b/ci/dev/vscode.patch index 00c05d9d3..3d7633753 100644 --- a/ci/dev/vscode.patch +++ b/ci/dev/vscode.patch @@ -1466,10 +1466,10 @@ index 0000000000000000000000000000000000000000..6ce56bec114a6d8daf5dd3ded945ea78 +} diff --git a/src/vs/server/node/channel.ts b/src/vs/server/node/channel.ts new file mode 100644 -index 0000000000000000000000000000000000000000..40779e80aa56d6b802d39f7170c9c94a997393ef +index 0000000000000000000000000000000000000000..95d0d3c51e4a25a9d7d0cada90d031c79bd86380 --- /dev/null +++ b/src/vs/server/node/channel.ts -@@ -0,0 +1,848 @@ +@@ -0,0 +1,860 @@ +import { field, logger } from '@coder/logger'; +import { Server } from '@coder/node-browser'; +import * as os from 'os'; @@ -1893,7 +1893,12 @@ index 0000000000000000000000000000000000000000..40779e80aa56d6b802d39f7170c9c94a + private readonly maxReplayData = 10000; + private totalReplayData = 0; + -+ private detached = false; ++ // According to the release notes the terminals are supposed to dispose after ++ // a short timeout; in our case we'll use 48 hours so you can get them back ++ // the next day or over the weekend. ++ private disposeTimeout: NodeJS.Timeout | undefined; ++ private disposeDelay = 48 * 60 * 60 * 1000; ++ + private buffering = false; + private readonly _onEvent = new Emitter({ + // Don't bind to data until something is listening. @@ -1907,11 +1912,15 @@ index 0000000000000000000000000000000000000000..40779e80aa56d6b802d39f7170c9c94a + + // Replay stored events. + onFirstListenerDidAdd: () => { -+ if (!this.detached) { ++ // We only need to replay if the terminal is being reconnected which is ++ // true if there is a dispose timeout. ++ if (typeof this.disposeTimeout !== "undefined") { + return; + } + -+ this.detached = false; ++ clearTimeout(this.disposeTimeout); ++ this.disposeTimeout = undefined; ++ + logger.debug('Terminal replaying', field('id', this.id)); + this._onEvent.fire({ + type: 'replay', @@ -1924,10 +1933,13 @@ index 0000000000000000000000000000000000000000..40779e80aa56d6b802d39f7170c9c94a + }, + + onLastListenerRemove: () => { -+ this.detached = true; + logger.debug('Terminal unbound', field('id', this.id)); + if (!this.persist) { // Used by debug consoles. + this.dispose(); ++ } else { ++ this.disposeTimeout = setTimeout(() => { ++ this.dispose(); ++ }, this.disposeDelay); + } + } + });