Skip to content
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

GH-8723: From now on, proxy factories do not wait for reconnect once the websocket connection was disposed #8803

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,21 @@
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/

import { ContainerModule } from 'inversify';
import { ContainerModule, interfaces } from 'inversify';
import { bindDynamicLabelProvider } from './label/sample-dynamic-label-provider-command-contribution';
import { bindSampleUnclosableView } from './view/sample-unclosable-view-contribution';
import { bindSampleOutputChannelWithSeverity } from './output/sample-output-channel-with-severity';
import { bindSampleMenu } from './menu/sample-menu-contribution';
import { bindSampleFileWatching } from './file-watching/sample-file-watching-contribution';
import { bindSampleShell } from './shell/sample-application-shell';

import '../../src/browser/style/branding.css';

export default new ContainerModule(bind => {
export default new ContainerModule((bind: interfaces.Bind, unbind: interfaces.Unbind, isBound: interfaces.IsBound, rebind: interfaces.Rebind) => {
bindDynamicLabelProvider(bind);
bindSampleUnclosableView(bind);
bindSampleOutputChannelWithSeverity(bind);
bindSampleMenu(bind);
bindSampleFileWatching(bind);
bindSampleShell(bind, unbind, isBound, rebind);
});
60 changes: 60 additions & 0 deletions examples/api-samples/src/browser/shell/sample-application-shell.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/********************************************************************************
* Copyright (C) 2020 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 { inject, injectable, interfaces } from 'inversify';
import { SaveOptions } from '@theia/core/lib/browser/saveable';
import { MessageService } from '@theia/core/lib/common/message-service';
import { ApplicationShell } from '@theia/core/lib/browser/shell/application-shell';
import { ConnectionStatus, FrontendConnectionStatusService } from '@theia/core/lib/browser/connection-status-service';

@injectable()
export class SampleApplicationShell extends ApplicationShell {

@inject(MessageService)
protected messageService: MessageService;

@inject(FrontendConnectionStatusService)
protected connectionStatusService: FrontendConnectionStatusService;

async saveAll(options?: SaveOptions): Promise<void> {
try {
await super.saveAll(options);
} catch (error) {
this.handleError(error);
}
}

async save(options?: SaveOptions): Promise<void> {
try {
await super.save(options);
} catch (error) {
this.handleError(error);
}
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
private handleError(error: any): void {
const message = this.connectionStatusService.currentStatus === ConnectionStatus.OFFLINE
? 'The backend process is not running. Please copy your unsaved work into your favorite text editor, and restart the IDE.'
: error instanceof Error ? error.message : String(error);
this.messageService.error(`Could not save the changes. ${message}`);
}

}

export const bindSampleShell = (bind: interfaces.Bind, unbind: interfaces.Unbind, isBound: interfaces.IsBound, rebind: interfaces.Rebind) => {
bind(SampleApplicationShell).toSelf().inSingletonScope();
rebind(ApplicationShell).toService(SampleApplicationShell);
};
8 changes: 7 additions & 1 deletion packages/core/src/common/messaging/proxy-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
/* eslint-disable @typescript-eslint/no-explicit-any */

import { MessageConnection, ResponseError } from 'vscode-jsonrpc';
import { environment } from '@theia/application-package/lib/environment';
import { ApplicationError } from '../application-error';
import { Event, Emitter } from '../event';
import { Disposable } from '../disposable';
Expand Down Expand Up @@ -140,7 +141,12 @@ export class JsonRpcProxyFactory<T extends object> implements ProxyHandler<T> {
}
}
}
connection.onDispose(() => this.waitForConnection());
connection.onDispose(() => {
// The electron frontend can't reconnect when the backend process is gone. (https://github.com/eclipse-theia/theia/issues/8723)
if (!environment.electron.is()) {
this.waitForConnection();
}
});
connection.listen();
this.connectionPromiseResolve(connection);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/node/backend-application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ export class BackendApplication {
entryTypes: ['measure']
});

this.initialize();
this.initialize().then(() => console.log(`Backend is up and running. [PID: ${process.pid}]`));
}

protected async initialize(): Promise<void> {
Expand Down
1 change: 1 addition & 0 deletions packages/monaco/src/browser/monaco-editor-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ export class MonacoEditorModel implements ITextEditorModel, TextEditorDocument {
await operation();
} catch (e) {
console.error(e);
throw e;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it does not throw on purpose to avoid rejecting consequent operations

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the note. Well, we should reject it somehow. That would be the desired flow when clients want to handle errors. If the error was swallowed on purpose, that's a problem. What was the problematic use-case?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can filter the error and rethrow only when it indicates t a connection disposed issue, but the rejection must happen, preferably always.

Copy link
Member

@akosyakov akosyakov Dec 1, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe something like:

const result = this.pendingOperation.then(() = operation());
this.pendingOperation = result.catch(e => console.error(e));
return result;

but we should also check all clients of run that they expect that now sync and save can throw and can deal with it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I will check the call sites. Thanks! Eventually, I am fine with introducing a new template method, handleError, with console.log(error) default implementation in the monaco-editor-model.ts module, but best would be to have the error handling in Theia.

}
});
}
Expand Down