Keep a maximum number of connections instead of a timeout

There's no way to actually know if those clients have gone away, so it
seems it might be better to base it on whether the user has connected
again with new clients to determine if the old clients are now invalid.
This commit is contained in:
Asher
2019-09-09 16:41:04 -05:00
parent 12e608468b
commit 1164801376
2 changed files with 50 additions and 36 deletions

View File

@@ -426,6 +426,7 @@ export class MainServer extends Server {
public readonly onDidClientConnect = this._onDidClientConnect.event;
private readonly ipc = new IPCServer(this.onDidClientConnect);
private readonly maxOfflineConnections = 5;
private readonly connections = new Map<ConnectionType, Map<string, Connection>>();
private readonly services = new ServiceCollection();
@@ -586,6 +587,7 @@ export class MainServer extends Server {
);
}
connections.set(token, connection);
this.disposeOldOfflineConnections();
connection.onClose(() => connections.delete(token));
break;
case ConnectionType.Tunnel: return protocol.tunnel();
@@ -593,6 +595,16 @@ export class MainServer extends Server {
}
}
private disposeOldOfflineConnections(): void {
this.connections.forEach((connections) => {
const offline = Array.from(connections.values())
.filter((connection) => typeof connection.offline !== "undefined");
for (let i = 0, max = offline.length - this.maxOfflineConnections; i < max; ++i) {
offline[i].dispose();
}
});
}
private async initializeServices(args: ParsedArgs): Promise<void> {
const environmentService = new EnvironmentService(args, process.execPath);
const logService = new SpdLogService(RemoteExtensionLogFileName, environmentService.logsPath, getLogLevel(environmentService));