New issue
Advanced search Search tips
Note: Color blocks (like or ) mean that a user may not be available. Tooltip shows the reason.

Issue 600972 link

Starred by 1 user

Issue metadata

Status: Archived
Owner:
Last visit > 30 days ago
Closed: Dec 2017
Components:
EstimatedDays: ----
NextAction: ----
OS: All
Pri: 3
Type: Bug



Sign in to add a comment

Log warning if running SW code outside of event handler

Reported by a...@scirra.com, Apr 6 2016

Issue description

UserAgent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2700.0 Safari/537.36

Steps to reproduce the problem:
It appears Chrome allows code in a SW to execute outside of an event handler. AFAIK the spec disallows this, and Firefox appears to terminate any code outside a SW event handler. This creates a portability headache (see https://www.scirra.com/blog/ashley/27/service-workers-are-a-pain-in-the-ass) since something like a background update check will appear to work in Chrome but fail in Firefox, and may fail in future in Chrome if it is updated to work like Firefox.

What is the expected behavior?
If code is running outside of a SW event handler, Chrome should either:
- terminate it, and log a message to the console that some code was terminated
- leave it running, but log a message to the console that code is running outside of an event handler

What went wrong?
It silently allows non-portable behavior, which creates a nasty gotcha for SW code.

Did this work before? N/A 

Chrome version: 51.0.2700.0  Channel: dev
OS Version: 10.0
Flash Version: Shockwave Flash 21.0 r0
 
By "outside an event handler" do you mean after event-extending promises (respondWith/waitUntil) have resolved? 

Comment 2 by a...@scirra.com, Apr 6 2016

Yes, exactly.
Components: -Platform>DevTools Blink>ServiceWorker
Labels: -OS-Windows -Pri-2 -Arch-x86_64 OS-All Pri-3
Perhaps a single warning if the SW runs code after an event is completed (so the SW is not guaranteed to be alive) would be useful. I'm a bit worried about log spam.

"Guaranteed to be alive" is a bit fuzzy. Strictly speaking the spec allows the user agent to terminate the worker at any time (timeouts).

Also, the spec allows running such code. Firefox also allows such code execution, in at least some cases. A quick test of setInterval() in onfetch shows the worker is running after it's guaranteed to stay alive. And indeed Firefox developers were supportive of allowing setTimeout() in service worker: https://github.com/slightlyoff/ServiceWorker/issues/838

Related:  issue 455540 

Comment 5 by bke...@mozilla.com, Apr 7 2016

How would you define this?  There can be multiple functional events in flight being extended by promises.  How can you know if any given chunk of async js code is part of one of those extended promises?

Or are you saying just when there have been no extended promises at all?  I guess that would work, but possibly miss some out-of-event code.

Note, we basically implement the same grace timer approach that chrome does.  So code can execute outside of the event.

Comment 6 by a...@scirra.com, Apr 7 2016

When using SW I found that Firefox was silently terminating some code because it wasn't in an extending promise. It was one of several gotchas that really confused the development process. I'm assuming Firefox is allowed to do that and not a bug, BTW. So I think there should just be a warning logged to the console if the SW is terminated - for any reason - while code is executing or there are promises in-flight. Maybe it could even cover termination while extended events are in-flight too, why not? Having code terminated mid-execution is surprising, and the developer should be informed so they're not left thinking "WTF", which I was thinking too many times while writing SW code.

Comment 7 by bke...@mozilla.com, Apr 7 2016

Logging when the service worker is timed out while running code is easier.  We have an open bug for that here:

  https://bugzilla.mozilla.org/show_bug.cgi?id=1167553

Also note, at one point chrome forced service workers to stay alive while devtools was opened.  I don't know if it still does that, but it might explain why you weren't seeing service workers killed outside of events there.
Components: Platform>DevTools
Owner: kenjibaheux@chromium.org
Status: Assigned (was: Unconfirmed)
> Also note, at one point chrome forced service workers to stay alive while devtools was opened.  I don't know if it still does that, but it might explain why you weren't seeing service workers killed outside of events there.

Yep, that's  issue 455540  I linked to above.

Maybe the best thing Chrome can do is:
- Fix  issue 455540 
- Fix  issue 457968  (but I don't know where we'd show error. when the SW is shutdown I believe the connection with DevTools is severed)

+DevTools for advice.

Owner: seththompson@chromium.org
Assigning this one back to V8's Seth.
Owner: eostroukhov@chromium.org
Status: Archived (was: Assigned)

Sign in to add a comment