Bug 1874782 Comment 2 Edit History

Note: The actual edited comment in the bug view page will always show the original commenter’s name and original timestamp.

From the log in [the comment](https://bugzilla.mozilla.org/show_bug.cgi?id=1861342#c14) I understand the issue to be that the SimpleTest infrastructure [is seeing that we still have registered ServiceWorkers](https://searchfox.org/mozilla-central/rev/f60bb10a5fe6936f9e9f9e8a90d52c18a0ffd818/testing/mochitest/tests/SimpleTest/SimpleTest.js#1508-1525).

I see that this seems to be the first test after restarting Firefox, and that [the last test in the preceding run](https://treeherder.mozilla.org/logviewer?job_id=457545266&repo=autoland&lineNumber=4151-4154) also seems to be a push test [dom/push/test/test_unregister.html](https://searchfox.org/mozilla-central/rev/f60bb10a5fe6936f9e9f9e8a90d52c18a0ffd818/dom/push/test/test_unregister.html).

The simplest explanation is that we are reusing the profile and the previous run shut down before having flushed `serviceworker.txt` to disk.  (That said, we have a shutdown blocker that should [block shutdown until we have flushed the data](https://searchfox.org/mozilla-central/rev/f60bb10a5fe6936f9e9f9e8a90d52c18a0ffd818/dom/serviceworkers/ServiceWorkerRegistrar.cpp#1045) ([calls-between diagram](https://searchfox.org/mozilla-central/query/default?q=calls-between-source%3A%27mozilla%3A%3Adom%3A%3AServiceWorkerRegistrar%3A%3ABlockShutdown%27+calls-between-target%3A%27mozilla%3A%3Adom%3A%3AServiceWorkerRegistrar%3A%3AShutdownCompleted%27+depth%3A8).)  The next alternative is that a functional event or soft update check has gone and begun to reinstall the ServiceWorker.  We do have delays in some update logic that use fairly simple runnables, so it wouldn't be shocking to find that these are responsible.  Unfortunately, it seems like this all only happens on windows, so it's not easy to just get a pernosco trace.

The push tests seems to use Math.random() in the cache-busting idiom that likely was advisable back in the days of ServiceWorker resurrection, but is now unnecessary because, as you found, unregister() should be reliable.  I would suggest changing the [unregister cache-busting](https://searchfox.org/mozilla-central/rev/f60bb10a5fe6936f9e9f9e8a90d52c18a0ffd818/dom/push/test/test_unregister.html#27) to be something deterministic like `return "worker.js?test_unregister.html";` and similarly [in test_permission_granted](https://searchfox.org/mozilla-central/rev/f60bb10a5fe6936f9e9f9e8a90d52c18a0ffd818/dom/push/test/test_permission_granted.html#15) too.  (Well, ideally, in all cases.)  This should help make it clear what the source of the bad SW is.
From the log in [the comment](https://bugzilla.mozilla.org/show_bug.cgi?id=1861342#c14) I understand the issue to be that the SimpleTest infrastructure [is seeing that we still have registered ServiceWorkers](https://searchfox.org/mozilla-central/rev/f60bb10a5fe6936f9e9f9e8a90d52c18a0ffd818/testing/mochitest/tests/SimpleTest/SimpleTest.js#1508-1525).

I see that this seems to be the first test after restarting Firefox, and that [the last test in the preceding run](https://treeherder.mozilla.org/logviewer?job_id=457545266&repo=autoland&lineNumber=4151-4154) also seems to be a push test [dom/push/test/test_unregister.html](https://searchfox.org/mozilla-central/rev/f60bb10a5fe6936f9e9f9e8a90d52c18a0ffd818/dom/push/test/test_unregister.html).

The simplest explanation is that we are reusing the profile and the previous run shut down before having flushed `serviceworker.txt` to disk.  (That said, we have a shutdown blocker that should [block shutdown until we have flushed the data](https://searchfox.org/mozilla-central/rev/f60bb10a5fe6936f9e9f9e8a90d52c18a0ffd818/dom/serviceworkers/ServiceWorkerRegistrar.cpp#1045) ([calls-between diagram](https://searchfox.org/mozilla-central/query/default?q=calls-between-source%3A%27mozilla%3A%3Adom%3A%3AServiceWorkerRegistrar%3A%3ABlockShutdown%27+calls-between-target%3A%27mozilla%3A%3Adom%3A%3AServiceWorkerRegistrar%3A%3AShutdownCompleted%27+depth%3A8)).)  The next alternative is that a functional event or soft update check has gone and begun to reinstall the ServiceWorker.  We do have delays in some update logic that use fairly simple runnables, so it wouldn't be shocking to find that these are responsible.  Unfortunately, it seems like this all only happens on windows, so it's not easy to just get a pernosco trace.

The push tests seems to use Math.random() in the cache-busting idiom that likely was advisable back in the days of ServiceWorker resurrection, but is now unnecessary because, as you found, unregister() should be reliable.  I would suggest changing the [unregister cache-busting](https://searchfox.org/mozilla-central/rev/f60bb10a5fe6936f9e9f9e8a90d52c18a0ffd818/dom/push/test/test_unregister.html#27) to be something deterministic like `return "worker.js?test_unregister.html";` and similarly [in test_permission_granted](https://searchfox.org/mozilla-central/rev/f60bb10a5fe6936f9e9f9e8a90d52c18a0ffd818/dom/push/test/test_permission_granted.html#15) too.  (Well, ideally, in all cases.)  This should help make it clear what the source of the bad SW is.

Back to Bug 1874782 Comment 2