-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Introduce timeout for keeping connection contexts alive #13082
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
Merged
tsmaeder
merged 7 commits into
eclipse-theia:master
from
tsmaeder:12823_persistent_back_end
Dec 18, 2023
Merged
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
e60cbd2
Introduce timeout for keeping connection contexts alive
tsmaeder b09f6af
Address linter issues
tsmaeder 23057cf
More linting problems
tsmaeder d619246
Fixing tests
tsmaeder 5b8a47c
Fix typo
tsmaeder 4b3e870
Address review comments
tsmaeder d2e6f9d
Fix remote development
tsmaeder File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
Introduce timeout for keeping connection contexts alive
Fixes #12823 - refactor front end to allow for multiple reconnections - remove IWebsockt abstractions - separate front end connections from service channel management - introduce mechanism to reconnect front end to existing connection context based on timeouts Contributed on behalf of STMicroelectronics Signed-off-by: Thomas Mäder <t.s.maeder@gmail.com>
- Loading branch information
commit e60cbd27f20da67fddee3f5c9e5d1f7d81d8284b
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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) 2023 STMicroelectronics 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-only WITH Classpath-exception-2.0 | ||
| // ***************************************************************************** | ||
|
|
||
| import { Channel, Event } from "../../common"; | ||
|
|
||
| export const ConnectionSource = Symbol('ConnectionSource'); | ||
|
|
||
| /** | ||
| * A ConnectionSource creates a Channel. The channel is valid until it sends a close event. | ||
| */ | ||
| export interface ConnectionSource { | ||
| onConnectionDidOpen: Event<Channel>; | ||
| } | ||
msujew marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
38 changes: 38 additions & 0 deletions
38
packages/core/src/browser/messaging/frontend-id-provider.ts
This file contains hidden or 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,38 @@ | ||
| // ***************************************************************************** | ||
| // Copyright (C) 2023 STMicroelectronics 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-only WITH Classpath-exception-2.0 | ||
| // ***************************************************************************** | ||
|
|
||
| import { injectable } from "inversify"; | ||
| import { generateUuid } from "../../common/uuid"; | ||
|
|
||
| export const FrontendIdProvider = Symbol('FrontendIdProvider'); | ||
|
|
||
| /** | ||
| * A FronendIdProvider computes an id for an instance of the front end that may be reconnected to a back end | ||
| * connection context. | ||
| */ | ||
| export interface FrontendIdProvider { | ||
| getId(): string; | ||
| } | ||
|
|
||
| @injectable() | ||
| export class BrowserFrontendIdProvider implements FrontendIdProvider { | ||
| protected readonly id = generateUuid(); // generate a new id each time we load the application | ||
|
|
||
| getId(): string { | ||
| return this.id; | ||
| } | ||
|
|
||
| } | ||
msujew marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
This file contains hidden or 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
127 changes: 127 additions & 0 deletions
127
packages/core/src/browser/messaging/service-connection-provider.ts
This file contains hidden or 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,127 @@ | ||
| // ***************************************************************************** | ||
| // Copyright (C) 2020 Ericsson 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-only WITH Classpath-exception-2.0 | ||
| // ***************************************************************************** | ||
|
|
||
| import { inject, injectable, interfaces, postConstruct } from 'inversify'; | ||
| import { Channel, RpcProxy, RpcProxyFactory } from '../../common'; | ||
| import { ChannelMultiplexer } from '../../common/message-rpc/channel'; | ||
| import { Deferred } from '../../common/promise-util'; | ||
| import { ConnectionSource } from './connection-source'; | ||
|
|
||
|
|
||
| export const LocalConnectionProvider = Symbol('LocalConnectionProvider'); | ||
| export const RemoteConnectionProvider = Symbol('RemoteConnectionProvider'); | ||
|
|
||
| export namespace ServiceConnectionProvider { | ||
| export type ConnectionHandler = (path: String, channel: Channel) => void; | ||
| } | ||
|
|
||
| /** | ||
| * This class manages the channels for remote services in the back end | ||
| */ | ||
| @injectable() | ||
| export class ServiceConnectionProvider { | ||
|
|
||
| static createProxy<T extends object>(container: interfaces.Container, path: string, arg?: object): RpcProxy<T> { | ||
| return container.get<ServiceConnectionProvider>(RemoteConnectionProvider).createProxy(path, arg); | ||
| } | ||
|
|
||
| static createLocalProxy<T extends object>(container: interfaces.Container, path: string, arg?: object): RpcProxy<T> { | ||
| return container.get<ServiceConnectionProvider>(LocalConnectionProvider).createProxy(path, arg); | ||
| } | ||
|
|
||
| static createHandler(container: interfaces.Container, path: string, arg?: object): void { | ||
| const remote = container.get<ServiceConnectionProvider>(RemoteConnectionProvider); | ||
| const local = container.get<ServiceConnectionProvider>(LocalConnectionProvider); | ||
| remote.createProxy(path, arg); | ||
| if (remote !== local) { | ||
| local.createProxy(path, arg); | ||
| } | ||
| } | ||
|
|
||
| protected readonly channelHandlers = new Map<string, ServiceConnectionProvider.ConnectionHandler>(); | ||
|
|
||
| /** | ||
| * Create a proxy object to remote interface of T type | ||
| * over a web socket connection for the given path and proxy factory. | ||
| */ | ||
| createProxy<T extends object>(path: string, factory: RpcProxyFactory<T>): RpcProxy<T>; | ||
| /** | ||
| * Create a proxy object to remote interface of T type | ||
| * over a web socket connection for the given path. | ||
| * | ||
| * An optional target can be provided to handle | ||
| * notifications and requests from a remote side. | ||
| */ | ||
| createProxy<T extends object>(path: string, target?: object): RpcProxy<T>; | ||
| createProxy<T extends object>(path: string, arg?: object): RpcProxy<T> { | ||
| const factory = arg instanceof RpcProxyFactory ? arg : new RpcProxyFactory<T>(arg); | ||
| this.listen(path, (_, c) => factory.listen(c), true); | ||
| return factory.createProxy(); | ||
| } | ||
|
|
||
| protected channelMultiplexer: ChannelMultiplexer; | ||
|
|
||
| private channelReadyDeferred = new Deferred<void>(); | ||
| protected get channelReady(): Promise<void> { | ||
| return this.channelReadyDeferred.promise; | ||
| } | ||
|
|
||
| @postConstruct() | ||
| init(): void { | ||
| this.connectionSource.onConnectionDidOpen(channel => this.handleChannelCreated(channel)); | ||
| } | ||
|
|
||
| @inject(ConnectionSource) | ||
| protected connectionSource: ConnectionSource; | ||
|
|
||
| /** | ||
| * This method must be invoked by subclasses when they have created the main channel. | ||
| * @param mainChannel | ||
| */ | ||
| protected handleChannelCreated(channel: Channel): void { | ||
| channel.onClose(() => { | ||
| this.handleChannelClosed(channel); | ||
| }); | ||
|
|
||
| this.channelMultiplexer = new ChannelMultiplexer(channel); | ||
| this.channelReadyDeferred.resolve(); | ||
| for (const entry of this.channelHandlers.entries()) { | ||
| this.openChannel(entry[0], entry[1]); | ||
| } | ||
| } | ||
|
|
||
| handleChannelClosed(channel: Channel): void { | ||
| this.channelReadyDeferred = new Deferred(); | ||
| } | ||
|
|
||
| /** | ||
| * Install a connection handler for the given path. | ||
| */ | ||
| listen(path: string, handler: ServiceConnectionProvider.ConnectionHandler, reconnect: boolean): void { | ||
| this.openChannel(path, handler).then(() => { | ||
| if (reconnect) { | ||
| this.channelHandlers.set(path, handler); | ||
| } | ||
| }); | ||
|
|
||
| } | ||
|
|
||
| private async openChannel(path: string, handler: ServiceConnectionProvider.ConnectionHandler): Promise<void> { | ||
| await this.channelReady; | ||
| const newChannel = await this.channelMultiplexer.open(path); | ||
| handler(path, newChannel); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.