You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Service worker code only supports a single content process #15217
Ok I'd like to fix this one, and I think this actually is a chance to change the infra for service worker a bit, and do something we haven't done yet: run something else than a script-thread in it's own process.
The issue mentioned above is essentially due to running the ServiceWorkerManager into the script-process(in multi-process mode), and having the constellation only have the ability to have one.
So we could enable the constellation to have senders to more than one manager, however, the real solution I think is to not actually run the ServiceWorkerManager in an EventLoop at all.
Instead, I think we should try to run each ServiceWorkerManager in their own process, and have the constellation own a map of ImmutableOrigin -> ServiceWorkerManager.
The ServiceWorkerManager would then be similar to an EventLoop, essentially a process running script code, however it would be running a service worker event-loop. Since service workers are supposed to be entirely event-driven, I think we can get away with running one thread per ServiceWorkerManager, which would run the event-loop for all service worker global scopes for a given origin.
Then, similar to what has already been done with WebGPU, the constellation would create a ServiceWorkerManager for a given origin when an EventLoop would first start using a ServiceWorker.
I think this is also important as a step to be able to fully implement service workers, since they are supposed to be shared on a per-origin basis across the entire browser(currently they are scoped to an EventLoop, meaning that there can be multiple ones for one origin when they are not part of the same browsing-context-group), and they are also supposed to be able to run when there is no window open at all, so by running them in their own process outside of an EventLoop, we both ensure there is only one per origin across the UA, and we also open the door to running them even when there are no EventLoop running.
since they are supposed to be shared on a per-origin basis across the entire browser (currently they are scoped to an EventLoop, meaning that there can be multiple ones for one origin when they are not part of the same browsing-context-group)
I haven't dig into Servo's SW infra though, I recently studied a little bit about SW and yes, I agree with on this!
In order to fix this issue, I would like to run the "service worker manager" in it's own process, and have the constellation own a map of "Origin" -> "Sender to a worker manager process".
That way, we don't start the ServiceWorkerManager in each content-process, instead, when a content-process starts using a service worker, it would send a message to the constellation, which could then either spin-up a manager for that origin, or simply keep using a manager that is already running for that origin.
After that, everytime a content-process needs to do an operation with the service worker, the message goes via the constellation and is forwarded to the manager running in its own process(this is what is currently done anyway, except that the manager runs in an EventLoop).
That way, at the cost of an additional process, we get a clearly isolated(from a business logic perspective) ServiceWorkerManager running all worker scope for a given origin, acting a bit like an EventLoop does for a script-thread.
I tried fixing it without introducing the new process, in #26073, and as noted in #7458 (comment), I think going that way would open a can of worms. It means we need to keep an EventLoop alive when it's running a worker manager that is(or could be) used by other EventLoops, and all sorts of other business logic that would go away if we just put the worker manager in it's own construct at the constellation level.
Also, with this structure, there is no logical difference between single- and multi-process mode. Essentially, the ServiceWorkerManager is an EventLoop-like construct that either runs in it's own process or not. The current problem in this issue is an example of how something can suddenly not work in a given mode, hence currently requires the code to be aware of the mode.
Finally, the spec puts a service worker in it's own agent-cluster, which doesn't necessarily mean it's own process, however it is the most straightforward way to actually do it.
@Manishearth@asajeffrey@jdm Since this is quite a change, please let me know what you think. I think this equally applies to fixing Service workers, as well as to a potential implementation of Shared workers(Actually both could potentially run in one process per origin, which I think could be an optimization making more sense then trying to co-locate them in a script-thread process).
Activity
gterzian commentedon Mar 29, 2020
Ok I'd like to fix this one, and I think this actually is a chance to change the infra for service worker a bit, and do something we haven't done yet: run something else than a script-thread in it's own process.
The issue mentioned above is essentially due to running the
ServiceWorkerManagerinto the script-process(in multi-process mode), and having the constellation only have the ability to have one.So we could enable the constellation to have senders to more than one manager, however, the real solution I think is to not actually run the
ServiceWorkerManagerin anEventLoopat all.Instead, I think we should try to run each
ServiceWorkerManagerin their own process, and have the constellation own a map ofImmutableOrigin->ServiceWorkerManager.The
ServiceWorkerManagerwould then be similar to anEventLoop, essentially a process running script code, however it would be running a service worker event-loop. Since service workers are supposed to be entirely event-driven, I think we can get away with running one thread perServiceWorkerManager, which would run the event-loop for all service worker global scopes for a given origin.Then, similar to what has already been done with
WebGPU, the constellation would create aServiceWorkerManagerfor a given origin when anEventLoopwould first start using aServiceWorker.I think this is also important as a step to be able to fully implement service workers, since they are supposed to be shared on a per-origin basis across the entire browser(currently they are scoped to an
EventLoop, meaning that there can be multiple ones for one origin when they are not part of the same browsing-context-group), and they are also supposed to be able to run when there is no window open at all, so by running them in their own process outside of anEventLoop, we both ensure there is only one per origin across the UA, and we also open the door to running them even when there are noEventLooprunning.@jdm what do you think of that proposal?
cc @CYBAI
CYBAI commentedon Mar 31, 2020
I haven't dig into Servo's SW infra though, I recently studied a little bit about SW and yes, I agree with on this!
gterzian commentedon Mar 31, 2020
Ok in the light of #7458 (comment) I will try to fix this without introducing more processes...
gterzian commentedon Apr 1, 2020
Ok as a bit of a recap of #7458 (comment)
ServiceWorkerManagerin each content-process, instead, when a content-process starts using a service worker, it would send a message to the constellation, which could then either spin-up a manager for that origin, or simply keep using a manager that is already running for that origin.EventLoop).That way, at the cost of an additional process, we get a clearly isolated(from a business logic perspective)
ServiceWorkerManagerrunning all worker scope for a given origin, acting a bit like anEventLoopdoes for a script-thread.I tried fixing it without introducing the new process, in #26073, and as noted in #7458 (comment), I think going that way would open a can of worms. It means we need to keep an
EventLoopalive when it's running a worker manager that is(or could be) used by otherEventLoops, and all sorts of other business logic that would go away if we just put the worker manager in it's own construct at the constellation level.Also, with this structure, there is no logical difference between single- and multi-process mode. Essentially, the
ServiceWorkerManageris anEventLoop-like construct that either runs in it's own process or not. The current problem in this issue is an example of how something can suddenly not work in a given mode, hence currently requires the code to be aware of the mode.Finally, the spec puts a service worker in it's own agent-cluster, which doesn't necessarily mean it's own process, however it is the most straightforward way to actually do it.
@Manishearth @asajeffrey @jdm Since this is quite a change, please let me know what you think. I think this equally applies to fixing Service workers, as well as to a potential implementation of Shared workers(Actually both could potentially run in one process per origin, which I think could be an optimization making more sense then trying to co-locate them in a script-thread process).
jdm commentedon Apr 2, 2020
I'm in favour!
Auto merge of #26087 - gterzian:allow_service_workers_in_multiprocess…
Auto merge of #26087 - gterzian:allow_service_workers_in_multiprocess…
Auto merge of #26087 - gterzian:allow_service_workers_in_multiprocess…
Auto merge of #26087 - gterzian:allow_service_workers_in_multiprocess…
Auto merge of #26087 - gterzian:allow_service_workers_in_multiprocess…
Auto merge of #26087 - gterzian:allow_service_workers_in_multiprocess…
Auto merge of #26087 - gterzian:allow_service_workers_in_multiprocess…
Auto merge of #26087 - gterzian:allow_service_workers_in_multiprocess…
Auto merge of #26087 - gterzian:allow_service_workers_in_multiprocess…
Auto merge of #26087 - gterzian:allow_service_workers_in_multiprocess…
Auto merge of #26087 - gterzian:allow_service_workers_in_multiprocess…
Auto merge of #26087 - gterzian:allow_service_workers_in_multiprocess…
Auto merge of #26087 - gterzian:allow_service_workers_in_multiprocess…