From 30136b0ef208a48042ecb1e18407ef525b772252 Mon Sep 17 00:00:00 2001 From: Akos Kitta Date: Thu, 22 Oct 2020 09:21:52 +0200 Subject: [PATCH] Capture and swallow unhandled SIGPIPE signal. To be able to work around the backend process crash and offline status. Ref: eclipse-theia/theia#8660 Signed-off-by: Akos Kitta --- .../src/node/arduino-ide-backend-module.ts | 6 +++++- .../node/theia/core/backend-application.ts | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 arduino-ide-extension/src/node/theia/core/backend-application.ts diff --git a/arduino-ide-extension/src/node/arduino-ide-backend-module.ts b/arduino-ide-extension/src/node/arduino-ide-backend-module.ts index 419cbc17..1eceee96 100644 --- a/arduino-ide-extension/src/node/arduino-ide-backend-module.ts +++ b/arduino-ide-extension/src/node/arduino-ide-backend-module.ts @@ -4,7 +4,7 @@ import { join } from 'path'; import { ContainerModule } from 'inversify'; import { ArduinoDaemonImpl } from './arduino-daemon-impl'; import { ILogger } from '@theia/core/lib/common/logger'; -import { BackendApplicationContribution } from '@theia/core/lib/node/backend-application'; +import { BackendApplicationContribution, BackendApplication as TheiaBackendApplication } from '@theia/core/lib/node/backend-application'; import { LibraryService, LibraryServicePath } from '../common/protocol/library-service'; import { BoardsService, BoardsServicePath } from '../common/protocol/boards-service'; import { LibraryServiceImpl } from './library-service-server-impl'; @@ -38,8 +38,12 @@ import { ExecutableServiceImpl } from './executable-service-impl'; import { OutputServicePath, OutputService } from '../common/protocol/output-service'; import { NotificationServiceServerImpl } from './notification-service-server'; import { NotificationServiceServer, NotificationServiceClient, NotificationServicePath } from '../common/protocol'; +import { BackendApplication } from './theia/core/backend-application'; export default new ContainerModule((bind, unbind, isBound, rebind) => { + bind(BackendApplication).toSelf().inSingletonScope(); + rebind(TheiaBackendApplication).toService(BackendApplication); + // Shared config service bind(ConfigFileValidator).toSelf().inSingletonScope(); bind(ConfigServiceImpl).toSelf().inSingletonScope(); diff --git a/arduino-ide-extension/src/node/theia/core/backend-application.ts b/arduino-ide-extension/src/node/theia/core/backend-application.ts new file mode 100644 index 00000000..c29da25b --- /dev/null +++ b/arduino-ide-extension/src/node/theia/core/backend-application.ts @@ -0,0 +1,19 @@ +import { inject, injectable, named } from 'inversify'; +import { ContributionProvider } from '@theia/core/lib/common/contribution-provider'; +import { BackendApplication as TheiaBackendApplication, BackendApplicationContribution, BackendApplicationCliContribution } from '@theia/core/lib/node/backend-application'; + +@injectable() +export class BackendApplication extends TheiaBackendApplication { + + constructor( + @inject(ContributionProvider) @named(BackendApplicationContribution) protected readonly contributionsProvider: ContributionProvider, + @inject(BackendApplicationCliContribution) protected readonly cliParams: BackendApplicationCliContribution + ) { + super(contributionsProvider, cliParams); + // Workaround for Electron not installing a handler to ignore SIGPIPE + // (https://github.com/electron/electron/issues/13254) + // From VS Code: https://github.com/microsoft/vscode/blob/d0c90c9f3ea8d34912194176241503a44b3abd80/src/bootstrap.js#L31-L37 + process.on('SIGPIPE', () => console.error(new Error('Unexpected SIGPIPE signal.'))); + } + +}