From 7d1da3818479e33141890a8f3d09557303331872 Mon Sep 17 00:00:00 2001 From: Cameron Diver Date: Tue, 17 Sep 2019 14:41:37 +0100 Subject: [PATCH] Catch and report cloud stream writing errors If an error fires when writing to the cloud stream, it can stop any calling processes from completing. Given that a logging failure should not cause other processes to cancel, we catch and report the error but otherwise do nothing else. Change-type: patch Signed-off-by: Cameron Diver --- src/logging/balena-backend.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/logging/balena-backend.ts b/src/logging/balena-backend.ts index 86c920d8..ceeb6999 100644 --- a/src/logging/balena-backend.ts +++ b/src/logging/balena-backend.ts @@ -203,8 +203,12 @@ export class BalenaLogBackend extends LogBackend { } if (this.writable) { - this.writable = this.stream.write(JSON.stringify(message) + '\n'); - this.flush(); + try { + this.writable = this.stream.write(JSON.stringify(message) + '\n'); + this.flush(); + } catch (e) { + log.error('Failed to write to logging stream, dropping message.', e); + } } else { this.dropCount += 1; }