Skip to content

Commit ae43e20

Browse files
committed
Handle up/down on server
1 parent 3f6cbfa commit ae43e20

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

src/node/channel.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -285,13 +285,15 @@ export class NodeProxyService implements INodeProxyService {
285285
public readonly onMessage = this._onMessage.event;
286286
private readonly _$onMessage = new Emitter<string>();
287287
public readonly $onMessage = this._$onMessage.event;
288-
private readonly _onClose = new Emitter<void>();
289-
public readonly onClose = this._onClose.event;
290-
private readonly _onDown = new Emitter<void>();
288+
public readonly _onDown = new Emitter<void>();
291289
public readonly onDown = this._onDown.event;
292-
private readonly _onUp = new Emitter<void>();
290+
public readonly _onUp = new Emitter<void>();
293291
public readonly onUp = this._onUp.event;
294292

293+
// Unused because the server connection will never permanently close.
294+
private readonly _onClose = new Emitter<void>();
295+
public readonly onClose = this._onClose.event;
296+
295297
public constructor() {
296298
// TODO: close/down/up
297299
const { Server } = localRequire<typeof import("@coder/node-browser/out/server/server")>("@coder/node-browser/out/server/server");

src/node/server.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ import { ExtensionEnvironmentChannel, FileProviderChannel, NodeProxyService } fr
6161
import { Connection, ExtensionHostConnection, ManagementConnection } from "vs/server/src/node/connection";
6262
import { TelemetryClient } from "vs/server/src/node/insights";
6363
import { getLocaleFromConfig, getNlsConfiguration } from "vs/server/src/node/nls";
64-
import { NodeProxyChannel } from "vs/server/src/common/nodeProxy";
64+
import { NodeProxyChannel, INodeProxyService } from "vs/server/src/common/nodeProxy";
6565
import { Protocol } from "vs/server/src/node/protocol";
6666
import { TelemetryChannel } from "vs/server/src/common/telemetry";
6767
import { UpdateService } from "vs/server/src/node/update";
@@ -621,6 +621,11 @@ export class MainServer extends Server {
621621
this._onDidClientConnect.fire({
622622
protocol, onDidClientDisconnect: connection.onClose,
623623
});
624+
// NOTE: We can do this because we only have one connection at a
625+
// time but if that changes we need a way to determine which clients
626+
// belong to a connection and dispose only those.
627+
(this.services.get(INodeProxyService) as NodeProxyService)._onUp.fire();
628+
connection.onClose(() => (this.services.get(INodeProxyService) as NodeProxyService)._onDown.fire());
624629
} else {
625630
const buffer = protocol.readEntireBuffer();
626631
connection = new ExtensionHostConnection(
@@ -695,6 +700,8 @@ export class MainServer extends Server {
695700
const instantiationService = new InstantiationService(this.services);
696701
const localizationService = instantiationService.createInstance(LocalizationsService);
697702
this.services.set(ILocalizationsService, localizationService);
703+
const proxyService = instantiationService.createInstance(NodeProxyService);
704+
this.services.set(INodeProxyService, proxyService);
698705
this.ipc.registerChannel("localizations", new LocalizationsChannel(localizationService));
699706
instantiationService.invokeFunction(() => {
700707
instantiationService.createInstance(LogsDataCleaner);
@@ -708,7 +715,7 @@ export class MainServer extends Server {
708715
const requestChannel = new RequestChannel(this.services.get(IRequestService) as IRequestService);
709716
const telemetryChannel = new TelemetryChannel(telemetryService);
710717
const updateChannel = new UpdateChannel(instantiationService.createInstance(UpdateService));
711-
const nodeProxyChannel = new NodeProxyChannel(instantiationService.createInstance(NodeProxyService));
718+
const nodeProxyChannel = new NodeProxyChannel(proxyService);
712719

713720
this.ipc.registerChannel("extensions", extensionsChannel);
714721
this.ipc.registerChannel("remoteextensionsenvironment", extensionsEnvironmentChannel);

0 commit comments

Comments
 (0)