From aa8d066fe16b1b8605f2287278899107e2a834ce Mon Sep 17 00:00:00 2001 From: Thomas Nordquist Date: Tue, 19 Mar 2019 18:30:29 +0100 Subject: [PATCH] Change execution order to mitigate exception effects For unknown reasons the "firstItem" is undefined in very rare cases. By changing the execution order, the drop will still work even if an exception occurs. --- backend/src/Model/RingBuffer.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/backend/src/Model/RingBuffer.ts b/backend/src/Model/RingBuffer.ts index 7b07bcb..1f74806 100644 --- a/backend/src/Model/RingBuffer.ts +++ b/backend/src/Model/RingBuffer.ts @@ -62,9 +62,11 @@ export class RingBuffer { } private dropFirst() { - const freedSpace = this.items[this.start].length - this.usage -= freedSpace + const firstItem = this.items[this.start] delete this.items[this.start] this.start += 1 + + const freedSpace = firstItem.length + this.usage -= freedSpace } }