Closed Bug 1176781 Opened 9 years ago Closed 4 years ago

Allow workers to be owners of shared workers

Categories

(Core :: DOM: Workers, defect, P5)

defect

Tracking

()

RESOLVED WONTFIX
Tracking Status
firefox41 --- affected

People

(Reporter: jrburke, Unassigned)

References

Details

(Keywords: dev-doc-needed)

According to the spec[1], right now only browser documents can be owners of a shared worker. 

However, with service workers and their use in Firefox OS browser system messages, like backgroundsync (request-sync as it is known currently), it is desirable to allow the service worker to communicate with a shared worker, with the service worker participating in the refcounting done for the shared worker that determines if the shared worker should stay up and running.

The request in this bug ticket is to allow other workers to be owners of a shared worker. If that general request would have problems, allowing just Service Workers would be enough for the use case.

The specific use case is the Email app on Firefox OS. It wants to periodically background sync. It also has an app UI that allows the user to do manual syncs, and send messages. We want a shared worker to handle the network and IndexedDB (IDB) work for all open app windows, and for background sync system messages.

There is a speculative example[2] that shows how email might use event.waitUntil in the service worker message listener to ask to keep the service worker alive while it messages with the shared worker to do the sync work.

The browser should still have some override heuristics that could decide to kill the service worker, and therefore the shared worker if no email browser windows open. Like for low memory cases where the foreground app needs the memory. However, if the browser wants to wait for the event.waitUntil promise to resolve, the shared worker communication should work.

The use case initially discussed in the backgroundsync repo[3], which led to the service worker repo issue[4].

There is a w3.org bugzilla bug[5] related to this request, and I started a whatwg thread[6] to see if there are any more concerns with this sort of change. The w3.org bug indicated that Presto already allows worker owners for shared workers, so it seems like there is some implementation precedence.

This request comes from the "next generation" app effort for Gaia in Firefox OS.

[1] https://html.spec.whatwg.org/multipage/workers.html#sharedworker
[2] https://github.com/slightlyoff/ServiceWorker/issues/678#issuecomment-92992257
[3] https://github.com/slightlyoff/BackgroundSync/issues/70
[4] https://github.com/slightlyoff/ServiceWorker/issues/678
[5] https://www.w3.org/Bugs/Public/show_bug.cgi?id=28504
[6] https://lists.w3.org/Archives/Public/public-whatwg-archive/2015Jun/0088.html
I think we tend call these "nested SharedWorkers".  I seem to recall either Ben or Kyle objected to implementing them in the past.
Priority: -- → P5

Marking this as WONTFIX because, post Firefox OS, any decisions around this would come out of discussions in https://github.com/whatwg/html/issues and/or https://github.com/w3c/ServiceWorker/issues/. Also, it's clear SharedWorkers have some lifecycle semantics issues and are no longer shipped by Webkit.

Disclaimer: I was involved in the original request and did think they were a good idea at the time! :)

Status: NEW → RESOLVED
Closed: 4 years ago
Resolution: --- → WONTFIX
You need to log in before you can comment on or make changes to this bug.