Gracefully handle disconnected frontends.

Signed-off-by: Akos Kitta <kittaakos@typefox.io>
This commit is contained in:
Akos Kitta 2019-11-12 10:24:53 +01:00
parent 2dc73eb3b5
commit df33c5689f
3 changed files with 27 additions and 3 deletions

View File

@ -38,10 +38,10 @@ export default new ContainerModule((bind, unbind, isBound, rebind) => {
bind(ArduinoCliContribution).toSelf().inSingletonScope();
bind(CliContribution).toService(ArduinoCliContribution);
// Provides the path of the Ardunio CLI.
// Provides the path of the Arduino CLI.
bind(ArduinoCli).toSelf().inSingletonScope();
// Shared daemonn
// Shared daemon
bind(ArduinoDaemon).toSelf().inSingletonScope();
bind(BackendApplicationContribution).toService(ArduinoDaemon);

View File

@ -10,6 +10,9 @@ import { ToolOutputServiceServer } from '../common/protocol/tool-output-service'
@injectable()
export class BoardsServiceImpl implements BoardsService {
@inject(ILogger)
protected logger: ILogger;
@inject(ILogger)
@named('discovery')
protected discoveryLogger: ILogger;
@ -95,9 +98,13 @@ export class BoardsServiceImpl implements BoardsService {
}
dispose(): void {
this.logger.info('>>> Disposing boards service...')
this.queue.pause();
this.queue.clear();
if (this.discoveryTimer !== undefined) {
clearInterval(this.discoveryTimer);
}
this.logger.info('<<< Disposed boards service.')
}
async getAttachedBoards(): Promise<{ boards: Board[] }> {

View File

@ -42,7 +42,24 @@ export class CoreClientProviderImpl implements CoreClientProvider {
async getClient(workspaceRootOrResourceUri?: string): Promise<Client | undefined> {
return this.clientRequestQueue.add(() => new Promise<Client | undefined>(async resolve => {
const roots = await this.workspaceServiceExt.roots();
let roots = undefined;
try {
roots = await this.workspaceServiceExt.roots();
} catch (e) {
if (e instanceof Error && e.message === 'Connection got disposed.') {
console.info('The frontend has already disconnected.');
// Ignore it for now: https://github.com/eclipse-theia/theia/issues/6499
// Client has disconnected, and the server still runs the serial board poll.
// The poll requires the client's workspace roots, but the client has disconnected :/
} else {
throw e;
}
}
if (!roots) {
resolve(undefined);
return
}
if (!workspaceRootOrResourceUri) {
resolve(this.getOrCreateClient(roots[0]));
return;