refactor: add worker id sanity check at message handling
authorJérôme Benoit <jerome.benoit@sap.com>
Sat, 5 Aug 2023 10:59:14 +0000 (12:59 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Sat, 5 Aug 2023 10:59:14 +0000 (12:59 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/worker/abstract-worker.ts

index b9e3deb08676f27aa7f2ab637e060f449811c11c..64627efb8823198c6cb09c81fbdded3bef046f01 100644 (file)
@@ -293,7 +293,9 @@ export abstract class AbstractWorker<
    * @param message - The received message.
    */
   protected messageListener (message: MessageValue<Data>): void {
-    if (message.workerId === this.id) {
+    if (message.workerId != null && message.workerId !== this.id) {
+      throw new Error('Message worker id does not match worker id')
+    } else if (message.workerId === this.id) {
       if (message.statistics != null) {
         // Statistics message received
         this.statistics = message.statistics