Fix a listener in tunnel service that's GC'ed without having been disposed (#214138)

This commit is contained in:
Alex Ross 2024-06-03 05:59:45 -07:00 committed by GitHub
parent 6908956c15
commit 8dd604a8d8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 7 additions and 6 deletions

View file

@ -5,7 +5,7 @@
import { CancellationToken } from 'vs/base/common/cancellation';
import { Emitter, Event } from 'vs/base/common/event';
import { IDisposable } from 'vs/base/common/lifecycle';
import { IDisposable, Disposable } from 'vs/base/common/lifecycle';
import { OperatingSystem } from 'vs/base/common/platform';
import { URI } from 'vs/base/common/uri';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
@ -215,7 +215,7 @@ export class DisposableTunnel {
}
}
export abstract class AbstractTunnelService implements ITunnelService {
export abstract class AbstractTunnelService extends Disposable implements ITunnelService {
declare readonly _serviceBrand: undefined;
private _onTunnelOpened: Emitter<RemoteTunnel> = new Emitter();
@ -234,7 +234,7 @@ export abstract class AbstractTunnelService implements ITunnelService {
public constructor(
@ILogService protected readonly logService: ILogService,
@IConfigurationService protected readonly configurationService: IConfigurationService
) { }
) { super(); }
get hasTunnelProvider(): boolean {
return !!this._tunnelProvider;
@ -308,7 +308,8 @@ export abstract class AbstractTunnelService implements ITunnelService {
return tunnels;
}
async dispose(): Promise<void> {
override async dispose(): Promise<void> {
super.dispose();
for (const portMap of this._tunnels.values()) {
for (const { value } of portMap.values()) {
await value.then(tunnel => typeof tunnel !== 'string' ? tunnel?.dispose() : undefined);

View file

@ -68,11 +68,11 @@ export class TunnelService extends AbstractTunnelService {
super(logService, configurationService);
// Destroy any shared process tunnels that might still be active
lifecycleService.onDidShutdown(() => {
this._register(lifecycleService.onDidShutdown(() => {
this._activeSharedProcessTunnels.forEach((id) => {
this._sharedProcessTunnelService.destroyTunnel(id);
});
});
}));
}
public isPortPrivileged(port: number): boolean {