{"action":"created","issue":{"url":"https://api.github.com/repos/w3c/ServiceWorker/issues/1146","repository_url":"https://api.github.com/repos/w3c/ServiceWorker","labels_url":"https://api.github.com/repos/w3c/ServiceWorker/issues/1146/labels{/name}","comments_url":"https://api.github.com/repos/w3c/ServiceWorker/issues/1146/comments","events_url":"https://api.github.com/repos/w3c/ServiceWorker/issues/1146/events","html_url":"https://github.com/w3c/ServiceWorker/issues/1146","id":229775860,"node_id":"MDU6SXNzdWUyMjk3NzU4NjA=","number":1146,"title":"\"Unregister\" operation may be interrupted by `ServiceWorker#postMessage`","user":{"login":"jugglinmike","id":677252,"node_id":"MDQ6VXNlcjY3NzI1Mg==","avatar_url":"https://avatars2.githubusercontent.com/u/677252?v=4","gravatar_id":"","url":"https://api.github.com/users/jugglinmike","html_url":"https://github.com/jugglinmike","followers_url":"https://api.github.com/users/jugglinmike/followers","following_url":"https://api.github.com/users/jugglinmike/following{/other_user}","gists_url":"https://api.github.com/users/jugglinmike/gists{/gist_id}","starred_url":"https://api.github.com/users/jugglinmike/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jugglinmike/subscriptions","organizations_url":"https://api.github.com/users/jugglinmike/orgs","repos_url":"https://api.github.com/users/jugglinmike/repos","events_url":"https://api.github.com/users/jugglinmike/events{/privacy}","received_events_url":"https://api.github.com/users/jugglinmike/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":{"login":"mattto","id":1782098,"node_id":"MDQ6VXNlcjE3ODIwOTg=","avatar_url":"https://avatars2.githubusercontent.com/u/1782098?v=4","gravatar_id":"","url":"https://api.github.com/users/mattto","html_url":"https://github.com/mattto","followers_url":"https://api.github.com/users/mattto/followers","following_url":"https://api.github.com/users/mattto/following{/other_user}","gists_url":"https://api.github.com/users/mattto/gists{/gist_id}","starred_url":"https://api.github.com/users/mattto/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mattto/subscriptions","organizations_url":"https://api.github.com/users/mattto/orgs","repos_url":"https://api.github.com/users/mattto/repos","events_url":"https://api.github.com/users/mattto/events{/privacy}","received_events_url":"https://api.github.com/users/mattto/received_events","type":"User","site_admin":false},"assignees":[{"login":"mattto","id":1782098,"node_id":"MDQ6VXNlcjE3ODIwOTg=","avatar_url":"https://avatars2.githubusercontent.com/u/1782098?v=4","gravatar_id":"","url":"https://api.github.com/users/mattto","html_url":"https://github.com/mattto","followers_url":"https://api.github.com/users/mattto/followers","following_url":"https://api.github.com/users/mattto/following{/other_user}","gists_url":"https://api.github.com/users/mattto/gists{/gist_id}","starred_url":"https://api.github.com/users/mattto/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mattto/subscriptions","organizations_url":"https://api.github.com/users/mattto/orgs","repos_url":"https://api.github.com/users/mattto/repos","events_url":"https://api.github.com/users/mattto/events{/privacy}","received_events_url":"https://api.github.com/users/mattto/received_events","type":"User","site_admin":false}],"milestone":null,"comments":7,"created_at":"2017-05-18T19:13:29Z","updated_at":"2019-06-06T13:31:47Z","closed_at":null,"author_association":"CONTRIBUTOR","body":"Consider the following code:\r\n\r\n```js\r\n// Precondition: `registration`is a valid ServiceWorkerRegistration object\r\n// whose \"active\" worker has no pending events\r\nregistration.unregister()\r\n  .then(function() {\r\n      registration.active.postMessage('');\r\n    });\r\n```\r\n\r\n\"unregistration\" involves the following sequence:\r\n\r\n1. **Queue a task** to resolve the promise (via Resolve Job Promise)\r\n2. If the active worker has no pending events (via Try Clear Registration)\r\n   1. Terminate the active worker (via Clear Registration)\r\n      1. Set the worker's \"closing\" flag to `true`\r\n   2. **Queue a task** to set the `state` attribute of the active worker to\r\n      \"redundant\" (via Update Worker State)\r\n   3. **Queue a task** to set the registration's `active` property to `null`\r\n      (via Update Registration State)\r\n\r\n\r\nThis means the `state` attribute is not set until *after* the promise has been\r\nresolved and any subsequent microtasks processed. Here, the `postMessage`\r\ninvocation is part of such a microtask, so when it references the worker's\r\n`state`, it receives the value \"active\". Execution of the `postMessage`\r\nalgorithm proceeds to step 4, where Run Service Worker is invoked. This creates\r\na new ServiceWorkerGlobalScope object, effectively undoing the prior invocation\r\nof Terminate Worker.\r\n\r\nChromium's behavior more or less adheres to this interpretation, although the\r\nworker's script is only evaluated one time (I would expect a second evaluation\r\nfor that invocation of Run Service Worker). Firefox throws an error named\r\n`NS_ERROR_FAILURE` from the `postMessage` invocation. In either case, this\r\nseems like a spec bug--the \"unregister\" operation is being interrupted, but the\r\nworker state is still ultimately set to \"redundant.\"\r\n\r\nDistinguishing between \"user-requested un-registration\" and \"user-agent\r\nrequested termination\" seems necessary in order to decide whether to throw or\r\nre-start the worker. Making this determination may not be possible from an\r\narbitrary `postMessage` invocation without the introduction of additional\r\nstate or a modification to the schedule of operations in Clear Registration."},"comment":{"url":"https://api.github.com/repos/w3c/ServiceWorker/issues/comments/499494875","html_url":"https://github.com/w3c/ServiceWorker/issues/1146#issuecomment-499494875","issue_url":"https://api.github.com/repos/w3c/ServiceWorker/issues/1146","id":499494875,"node_id":"MDEyOklzc3VlQ29tbWVudDQ5OTQ5NDg3NQ==","user":{"login":"wanderview","id":1256526,"node_id":"MDQ6VXNlcjEyNTY1MjY=","avatar_url":"https://avatars2.githubusercontent.com/u/1256526?v=4","gravatar_id":"","url":"https://api.github.com/users/wanderview","html_url":"https://github.com/wanderview","followers_url":"https://api.github.com/users/wanderview/followers","following_url":"https://api.github.com/users/wanderview/following{/other_user}","gists_url":"https://api.github.com/users/wanderview/gists{/gist_id}","starred_url":"https://api.github.com/users/wanderview/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wanderview/subscriptions","organizations_url":"https://api.github.com/users/wanderview/orgs","repos_url":"https://api.github.com/users/wanderview/repos","events_url":"https://api.github.com/users/wanderview/events{/privacy}","received_events_url":"https://api.github.com/users/wanderview/received_events","type":"User","site_admin":false},"created_at":"2019-06-06T13:31:47Z","updated_at":"2019-06-06T13:31:47Z","author_association":"MEMBER","body":"I feel like postMessage() throwing is somewhat unexpected.  For example, we don't do that in cases where the other end of MessageChannel is gone.  I would be more in favor of sending the message to /dev/null, maybe with a console warning."}}
{"actor":{"display_login":"wanderview"}}