Reconnect on interrupted system call.

However, we have to figure out why does it happen at all.

Signed-off-by: Akos Kitta <kittaakos@typefox.io>
This commit is contained in:
Akos Kitta
2019-11-30 15:54:49 +01:00
parent 9efcbcf2ae
commit eb7b3ad683
4 changed files with 76 additions and 47 deletions

View File

@@ -32,13 +32,14 @@ export class MonitorConnection {
@postConstruct()
protected init(): void {
this.monitorServiceClient.onError(error => {
this.monitorServiceClient.onError(async error => {
let shouldReconnect = false;
if (this.state) {
const { code, connectionId, config } = error;
if (this.state.connectionId === connectionId) {
switch (code) {
case MonitorError.ErrorCodes.CLIENT_CANCEL: {
console.log(`Connection was canceled by client: ${MonitorConnection.State.toString(this.state)}.`);
console.debug(`Connection was canceled by client: ${MonitorConnection.State.toString(this.state)}.`);
break;
}
case MonitorError.ErrorCodes.DEVICE_BUSY: {
@@ -51,8 +52,17 @@ export class MonitorConnection {
this.messageService.info(`Disconnected from ${Port.toString(port)}.`);
break;
}
case MonitorError.ErrorCodes.interrupted_system_call: {
const { board, port } = config;
this.messageService.warn(`Unexpectedly interrupted by backend. Reconnecting ${Board.toString(board)} on port ${Port.toString(port)}.`);
shouldReconnect = true;
}
}
const oldState = this.state;
this.state = undefined;
if (shouldReconnect) {
await this.connect(oldState.config);
}
} else {
console.warn(`Received an error from unexpected connection: ${MonitorConnection.State.toString({ connectionId, config })}.`);
}