Bug 180329 - Implement self.skipWaiting() inside service workers
Summary: Implement self.skipWaiting() inside service workers
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebCore Misc. (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Chris Dumez
URL:
Keywords: InRadar
Depends on:
Blocks: 180328
  Show dependency treegraph
 
Reported: 2017-12-02 23:23 PST by Chris Dumez
Modified: 2017-12-04 13:23 PST (History)
6 users (show)

See Also:


Attachments
Patch (24.43 KB, patch)
2017-12-02 23:53 PST, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (24.54 KB, patch)
2017-12-02 23:56 PST, Chris Dumez
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Chris Dumez 2017-12-02 23:23:45 PST
Implement self.skipWaiting() inside service workers.
Comment 1 Chris Dumez 2017-12-02 23:53:41 PST
Created attachment 328285 [details]
Patch
Comment 2 Chris Dumez 2017-12-02 23:56:54 PST
Created attachment 328286 [details]
Patch
Comment 3 WebKit Commit Bot 2017-12-03 12:33:01 PST
Comment on attachment 328286 [details]
Patch

Clearing flags on attachment: 328286

Committed r225460: <https://trac.webkit.org/changeset/225460>
Comment 4 WebKit Commit Bot 2017-12-03 12:33:03 PST
All reviewed patches have been landed.  Closing bug.
Comment 5 Radar WebKit Bug Importer 2017-12-03 12:34:19 PST
<rdar://problem/35820007>
Comment 6 youenn fablet 2017-12-03 14:08:53 PST
View in context: https://bugs.webkit.org/attachment.cgi?id=328286&action=review

> Source/WebCore/workers/service/ServiceWorkerGlobalScope.cpp:56
> +                thread().runLoop().postTask([promise = WTFMove(promise), protectedThis = WTFMove(protectedThis)](auto&) {

I wonder what ensures thread() to be valid at that point.
Is there anything that prevents the worker to be terminated and the run loop to be stopped?
Comment 7 Chris Dumez 2017-12-03 14:41:46 PST
(In reply to youenn fablet from comment #6)
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=328286&action=review
> 
> > Source/WebCore/workers/service/ServiceWorkerGlobalScope.cpp:56
> > +                thread().runLoop().postTask([promise = WTFMove(promise), protectedThis = WTFMove(protectedThis)](auto&) {
> 
> I wonder what ensures thread() to be valid at that point.
> Is there anything that prevents the worker to be terminated and the run loop
> to be stopped?

The WorkerThread stays alive longer that the WorkerGlobalScope, which is why WorkerGlobalScope::m_thread is a WorkerThread&. I do ref the WorkerGlobalScope here so if accessing thread() should be safe AFAICT.
Comment 8 youenn fablet 2017-12-03 21:01:02 PST
(In reply to Chris Dumez from comment #7)
> (In reply to youenn fablet from comment #6)
> > View in context:
> > https://bugs.webkit.org/attachment.cgi?id=328286&action=review
> > 
> > > Source/WebCore/workers/service/ServiceWorkerGlobalScope.cpp:56
> > > +                thread().runLoop().postTask([promise = WTFMove(promise), protectedThis = WTFMove(protectedThis)](auto&) {
> > 
> > I wonder what ensures thread() to be valid at that point.
> > Is there anything that prevents the worker to be terminated and the run loop
> > to be stopped?
> 
> The WorkerThread stays alive longer that the WorkerGlobalScope, which is why
> WorkerGlobalScope::m_thread is a WorkerThread&. I do ref the
> WorkerGlobalScope here so if accessing thread() should be safe AFAICT.

I might be missing something here.
I am not sure how we can guarantee that WorkerThread always stays alive longer than WorkerGlobalScope.
They have different refcounts.

Also, even if not destroyed, it seems feasible with the patch that we will post a task on a closed worker thread/message queue.
In that case, I would guess that the task will not be executed/destroyed on the worker thread. I haven't looked at how postTask/messageQueue works precisely so maybe I am misunderstanding something here. Let's discuss this in person tomorrow.
Comment 9 Chris Dumez 2017-12-04 13:23:45 PST
(In reply to youenn fablet from comment #8)
> (In reply to Chris Dumez from comment #7)
> > (In reply to youenn fablet from comment #6)
> > > View in context:
> > > https://bugs.webkit.org/attachment.cgi?id=328286&action=review
> > > 
> > > > Source/WebCore/workers/service/ServiceWorkerGlobalScope.cpp:56
> > > > +                thread().runLoop().postTask([promise = WTFMove(promise), protectedThis = WTFMove(protectedThis)](auto&) {
> > > 
> > > I wonder what ensures thread() to be valid at that point.
> > > Is there anything that prevents the worker to be terminated and the run loop
> > > to be stopped?
> > 
> > The WorkerThread stays alive longer that the WorkerGlobalScope, which is why
> > WorkerGlobalScope::m_thread is a WorkerThread&. I do ref the
> > WorkerGlobalScope here so if accessing thread() should be safe AFAICT.
> 
> I might be missing something here.
> I am not sure how we can guarantee that WorkerThread always stays alive
> longer than WorkerGlobalScope.
> They have different refcounts.
> 
> Also, even if not destroyed, it seems feasible with the patch that we will
> post a task on a closed worker thread/message queue.
> In that case, I would guess that the task will not be executed/destroyed on
> the worker thread. I haven't looked at how postTask/messageQueue works
> precisely so maybe I am misunderstanding something here. Let's discuss this
> in person tomorrow.

Filed https://bugs.webkit.org/show_bug.cgi?id=180372.