[whatwg] race condition in postMessage

Jonas Sicking jonas at sicking.cc
Thu Aug 21 17:17:06 PDT 2008


There is a race condition in proposed new Web Workers spec. The return 
value from postMessage can in some cases be true, even if the worker 
never receives the message.

For example:

main.js:

w = new DedicatedWorker("worker.js");
if (w.postMessage("hello there")) {
   alert("success!!");
}


worker.js:

close();


If the postMessage is called before the worker has executed the 
'close()' call the function will return true. But if the worker starts 
up fast enough and calls close(), the function will return false.

To put it another way. Even if the worker is currently up and running 
when postMessage is called, there is no guarantee that the worker will 
run long enough to actually get to process the message.

The only solution I can see is making postMessage return void. What use 
cases require knowing that the postMessage succeeds?

/ Jonas



More information about the whatwg mailing list