Archived
1
0

Add timeout for disposing detached terminals

This commit is contained in:
Asher 2020-11-19 11:21:15 -06:00
parent 1feb30a7ff
commit a6f8840009
No known key found for this signature in database
GPG Key ID: D63C1EF81242354A

View File

@ -1466,10 +1466,10 @@ index 0000000000000000000000000000000000000000..6ce56bec114a6d8daf5dd3ded945ea78
+} +}
diff --git a/src/vs/server/node/channel.ts b/src/vs/server/node/channel.ts diff --git a/src/vs/server/node/channel.ts b/src/vs/server/node/channel.ts
new file mode 100644 new file mode 100644
index 0000000000000000000000000000000000000000..40779e80aa56d6b802d39f7170c9c94a997393ef index 0000000000000000000000000000000000000000..95d0d3c51e4a25a9d7d0cada90d031c79bd86380
--- /dev/null --- /dev/null
+++ b/src/vs/server/node/channel.ts +++ b/src/vs/server/node/channel.ts
@@ -0,0 +1,848 @@ @@ -0,0 +1,860 @@
+import { field, logger } from '@coder/logger'; +import { field, logger } from '@coder/logger';
+import { Server } from '@coder/node-browser'; +import { Server } from '@coder/node-browser';
+import * as os from 'os'; +import * as os from 'os';
@ -1893,7 +1893,12 @@ index 0000000000000000000000000000000000000000..40779e80aa56d6b802d39f7170c9c94a
+ private readonly maxReplayData = 10000; + private readonly maxReplayData = 10000;
+ private totalReplayData = 0; + 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 buffering = false;
+ private readonly _onEvent = new Emitter<terminal.IRemoteTerminalProcessEvent>({ + private readonly _onEvent = new Emitter<terminal.IRemoteTerminalProcessEvent>({
+ // Don't bind to data until something is listening. + // Don't bind to data until something is listening.
@ -1907,11 +1912,15 @@ index 0000000000000000000000000000000000000000..40779e80aa56d6b802d39f7170c9c94a
+ +
+ // Replay stored events. + // Replay stored events.
+ onFirstListenerDidAdd: () => { + 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; + return;
+ } + }
+ +
+ this.detached = false; + clearTimeout(this.disposeTimeout);
+ this.disposeTimeout = undefined;
+
+ logger.debug('Terminal replaying', field('id', this.id)); + logger.debug('Terminal replaying', field('id', this.id));
+ this._onEvent.fire({ + this._onEvent.fire({
+ type: 'replay', + type: 'replay',
@ -1924,10 +1933,13 @@ index 0000000000000000000000000000000000000000..40779e80aa56d6b802d39f7170c9c94a
+ }, + },
+ +
+ onLastListenerRemove: () => { + onLastListenerRemove: () => {
+ this.detached = true;
+ logger.debug('Terminal unbound', field('id', this.id)); + logger.debug('Terminal unbound', field('id', this.id));
+ if (!this.persist) { // Used by debug consoles. + if (!this.persist) { // Used by debug consoles.
+ this.dispose(); + this.dispose();
+ } else {
+ this.disposeTimeout = setTimeout(() => {
+ this.dispose();
+ }, this.disposeDelay);
+ } + }
+ } + }
+ }); + });