forked from eclipse-theia/theia
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
eclipse-theiaGH-6499: Explicitly close the socket
onStop
in electron
Otherwise, the channels will be closed with a `checkAliveTimeout` delay in the electron application, when refreshing the browser window. Closes: eclipse-theia#6499 Signed-off-by: Akos Kitta <kittaakos@typefox.io>
- Loading branch information
Showing
8 changed files
with
93 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
packages/core/src/electron-browser/messaging/electron-messaging-frontend-module.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/******************************************************************************** | ||
* Copyright (C) 2019 TypeFox and others. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* This Source Code may also be made available under the following Secondary | ||
* Licenses when the conditions for such availability set forth in the Eclipse | ||
* Public License v. 2.0 are satisfied: GNU General Public License, version 2 | ||
* with the GNU Classpath Exception which is available at | ||
* https://www.gnu.org/software/classpath/license.html. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
********************************************************************************/ | ||
|
||
import { ContainerModule } from 'inversify'; | ||
import { FrontendApplicationContribution } from '../../browser/frontend-application'; | ||
import { WebSocketConnectionProvider } from '../../browser/messaging/ws-connection-provider'; | ||
import { ElectronWebSocketConnectionProvider } from './electron-ws-connection-provider'; | ||
|
||
export const messagingFrontendModule = new ContainerModule(bind => { | ||
bind(ElectronWebSocketConnectionProvider).toSelf().inSingletonScope(); | ||
bind(FrontendApplicationContribution).toService(ElectronWebSocketConnectionProvider); | ||
bind(WebSocketConnectionProvider).toService(ElectronWebSocketConnectionProvider); | ||
}); |
47 changes: 47 additions & 0 deletions
47
packages/core/src/electron-browser/messaging/electron-ws-connection-provider.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/******************************************************************************** | ||
* Copyright (C) 2019 TypeFox and others. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* This Source Code may also be made available under the following Secondary | ||
* Licenses when the conditions for such availability set forth in the Eclipse | ||
* Public License v. 2.0 are satisfied: GNU General Public License, version 2 | ||
* with the GNU Classpath Exception which is available at | ||
* https://www.gnu.org/software/classpath/license.html. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
********************************************************************************/ | ||
|
||
import { injectable } from 'inversify'; | ||
import { WebSocketChannel } from '../../common/messaging/web-socket-channel'; | ||
import { WebSocketConnectionProvider, WebSocketOptions } from '../../browser/messaging/ws-connection-provider'; | ||
import { FrontendApplicationContribution } from '../../browser/frontend-application'; | ||
|
||
@injectable() | ||
export class ElectronWebSocketConnectionProvider extends WebSocketConnectionProvider implements FrontendApplicationContribution { | ||
|
||
/** | ||
* Do not try to reconnect when the frontend application is stopping. The browser is navigating away from this page. | ||
*/ | ||
protected stopping = false; | ||
|
||
onStop(): void { | ||
this.stopping = true; | ||
// 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 | ||
for (const channel of [...this.channels.values()]) { | ||
// `1001` indicates that an endpoint is "going away", such as a server going down or a browser having navigated away from a page. | ||
// But we cannot use `1001`: https://github.com/TypeFox/vscode-ws-jsonrpc/issues/15 | ||
channel.close(1000, 'The frontend is "going away"...'); | ||
} | ||
} | ||
|
||
openChannel(path: string, handler: (channel: WebSocketChannel) => void, options?: WebSocketOptions): void { | ||
if (!this.stopping) { | ||
super.openChannel(path, handler, options); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters