Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop reconnection loop when the connection is disposed #174439

Merged
merged 1 commit into from Feb 15, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 9 additions & 4 deletions src/vs/platform/remote/common/remoteAgentConnection.ts
Expand Up @@ -583,7 +583,8 @@ export abstract class PersistentConnection extends Disposable {
return this._permanentFailure || PersistentConnection._permanentFailure;
}

private _isReconnecting: boolean;
private _isReconnecting: boolean = false;
private _isDisposed: boolean = false;

constructor(
private readonly _connectionType: ConnectionType,
Expand All @@ -593,7 +594,6 @@ export abstract class PersistentConnection extends Disposable {
private readonly _reconnectionFailureIsFatal: boolean
) {
super();
this._isReconnecting = false;

this._onDidStateChange.fire(new ConnectionGainEvent(this.reconnectionToken, 0, 0));

Expand Down Expand Up @@ -640,6 +640,11 @@ export abstract class PersistentConnection extends Disposable {
}
}

public override dispose(): void {
super.dispose();
this._isDisposed = true;
}

private async _beginReconnecting(): Promise<void> {
// Only have one reconnection loop active at a time.
if (this._isReconnecting) {
Expand All @@ -654,7 +659,7 @@ export abstract class PersistentConnection extends Disposable {
}

private async _runReconnectingLoop(): Promise<void> {
if (this._isPermanentFailure) {
if (this._isPermanentFailure || this._isDisposed) {
// no more attempts!
return;
}
Expand Down Expand Up @@ -735,7 +740,7 @@ export abstract class PersistentConnection extends Disposable {
this._onReconnectionPermanentFailure(this.protocol.getMillisSinceLastIncomingData(), attempt + 1, false);
break;
}
} while (!this._isPermanentFailure);
} while (!this._isPermanentFailure && !this._isDisposed);
}

private _onReconnectionPermanentFailure(millisSinceLastIncomingData: number, attempt: number, handled: boolean): void {
Expand Down