Skip to content

Commit

Permalink
GH-6499: Explicitly close the socket onStop.
Browse files Browse the repository at this point in the history
Otherwise, the channels will be closed with a `checkAliveTimeout` delay
in the electron application, when refreshing the browser window.

Closes: #6499
Signed-off-by: Akos Kitta <kittaakos@typefox.io>
  • Loading branch information
Akos Kitta committed Dec 2, 2019
1 parent c4b4d39 commit d7b832f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
********************************************************************************/

import { ContainerModule } from 'inversify';
import { FrontendApplicationContribution } from '../frontend-application';
import { WebSocketConnectionProvider } from './ws-connection-provider';

export const messagingFrontendModule = new ContainerModule(bind => {
bind(WebSocketConnectionProvider).toSelf().inSingletonScope();
bind(FrontendApplicationContribution).toService(WebSocketConnectionProvider);
});
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { injectable, interfaces, decorate, unmanaged } from 'inversify';
import { createWebSocketConnection, Logger, ConsoleLogger } from 'vscode-ws-jsonrpc/lib';
import { ConnectionHandler, JsonRpcProxyFactory, JsonRpcProxy, Emitter, Event } from '../../common';
import { WebSocketChannel } from '../../common/messaging/web-socket-channel';
import { FrontendApplicationContribution } from '../frontend-application';
import { Endpoint } from '../endpoint';
import ReconnectingWebSocket from 'reconnecting-websocket';

Expand All @@ -32,7 +33,7 @@ export interface WebSocketOptions {
}

@injectable()
export class WebSocketConnectionProvider {
export class WebSocketConnectionProvider implements FrontendApplicationContribution {

/**
* Create a proxy object to remote interface of T type
Expand Down Expand Up @@ -80,6 +81,12 @@ export class WebSocketConnectionProvider {
this.socket = socket;
}

onStop(): void {
// Close the websocket connection `onStop`. Otherwise, the channels will be closed with 30 sec (`MessagingContribution#checkAliveTimeout`) delay.
// https://github.com/eclipse-theia/theia/issues/6499
this.socket.close();
}

/**
* Create a proxy object to remote interface of T type
* over a web socket connection for the given path and proxy factory.
Expand Down

0 comments on commit d7b832f

Please sign in to comment.