[ServiceWorker] Race when registering multiple service workers for the same scope (#783)

Consider a sequence of two register() calls for two worker scripts on the same scope. The first service worker rejects its install event waitUntil promise after *some* time, resulting in the
registration being cleared. If the second register() is called while the first service worker is in the installing state but hasn't rejected yet, it may end up completing with a registration that was removed from the scope to registration map.

The order of events is as follows:
0. call register() for the first service worker
1. registration1 is at step 14 from the Install Algorithm: Wait for task to have executed or been discarded.
2. call register() for the second service worker.
3. registration2 hits step 4.1 from the Register Algorithm. This steps invokes Get Registration and will find
the registration created by the previous call.
4. registration2 executes atomically all the way to step 3 from Update
5. the first sw rejects and registration1 hits 16.3.1 from the Install Algorithm: Invoke Clear Registration
6. registration2 hits step 4.2 and continues with the update steps using a registration that was removed from the registration map when Clear Registration was invoked above.

This can happen because step 4.2 from Update can race with step 15 from Install. 

---
Reply to this email directly or view it on GitHub:
https://github.com/slightlyoff/ServiceWorker/issues/783

Received on Thursday, 19 November 2015 14:34:29 UTC