From 1e8560f53cba4f5c0d38bbf0de70e79ae4a8e184 Mon Sep 17 00:00:00 2001 From: Szymon Lesisz Date: Thu, 16 Apr 2020 13:32:10 +0200 Subject: [PATCH 1/2] fix trezord unexpected message loop --- src/js/device/DeviceCommands.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/js/device/DeviceCommands.js b/src/js/device/DeviceCommands.js index bfe9369ba..8dc2be42b 100644 --- a/src/js/device/DeviceCommands.js +++ b/src/js/device/DeviceCommands.js @@ -635,7 +635,15 @@ export default class DeviceCommands { } const response: DefaultMessageResponse = await this._commonCall(type, msg); - assertType(response, resType); + try { + assertType(response, resType); + } catch (error) { + // handle possible race condition + // Bridge has some unread message in buffer, read them + await this.transport.read(this.sessionId, false); + // throw error anyway, next call should be resolved properly + throw error; + } return response; } From f3d2cf73173d56de50d787346623cb69cf1954ed Mon Sep 17 00:00:00 2001 From: Szymon Lesisz Date: Thu, 16 Apr 2020 13:54:04 +0200 Subject: [PATCH 2/2] Update DeviceCommands.js --- src/js/device/DeviceCommands.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/js/device/DeviceCommands.js b/src/js/device/DeviceCommands.js index 8dc2be42b..6ccb70237 100644 --- a/src/js/device/DeviceCommands.js +++ b/src/js/device/DeviceCommands.js @@ -639,7 +639,7 @@ export default class DeviceCommands { assertType(response, resType); } catch (error) { // handle possible race condition - // Bridge has some unread message in buffer, read them + // Bridge may have some unread message in buffer, read it await this.transport.read(this.sessionId, false); // throw error anyway, next call should be resolved properly throw error;