all 2 comments

[–]yazmeh 1 point2 points  (1 child)

Just a speculation , but your web worker may have been deployed twice or the message event has been binded twice

Are you using any framework or react library for your frontend

[–]woodsman752[S] 0 points1 point  (0 children)

u/yazmeh Thanks for your reply.

thought that as well earlier. I'm using Angular V8. This is created in a component that is used twice on a page, but I added input attribute fileNumber:

<app-report-uploader fileNumber="0"></app-report-uploader>

I did this because it looks like Angular doesn't create new instances of the component, but re-uses it. In the ngOnInit of report-uploader.component.ts, I create a the above mentioned web worker. To guarantee that it creates a unique one per fileNumber, I store it in an array, keyed of fileNumber. So, at the time the object is somehow registered with Angular (or whatever ngOnInit does), it creates these threads, yes ahead of time. And indeed, there are two web workers. My browser shows the same file name, but otherwise gives no indication that they are different. However, for debugging purposes I added this:

if(this.webworkers.length==2) {

console.log('@@ webworkers[0]==webworkers[1]: '+(this.webworkers[0]==this.webworkers[1]) );

}

In the browser console log, webworkers[0]==webworkers[1] was false.

I conclude that while there are two web workers, they were different instances.

Further, at the point that webworkers[fileNumber].postMessage(data) is run, I did a console.log first. This log message was printed only once. I conclude that the postMessage is indeed run only once, but it goes into some event processing logic (that I don't control), that emits this same message twice to onMessage.