Bug 173745 - Consistently use RunLoop::isMain() in WebKit2
Summary: Consistently use RunLoop::isMain() in WebKit2
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebKit2 (show other bugs)
Version: WebKit Local Build
Hardware: All All
: P2 Normal
Assignee: Chris Dumez
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2017-06-22 16:47 PDT by Daniel Bates
Modified: 2017-06-23 14:18 PDT (History)
11 users (show)

See Also:


Attachments
Patch (28.80 KB, patch)
2017-06-22 18:55 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (28.80 KB, patch)
2017-06-22 19:00 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (29.01 KB, patch)
2017-06-22 19:27 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (28.93 KB, patch)
2017-06-23 13:50 PDT, 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 Daniel Bates 2017-06-22 16:47:36 PDT
In bug #173738, we substituted RunLoop:Main() for WTF::isMainThread() only in file Source/WebKit2/UIProcess/GenericCallback.h with the explanation "We have verified locally that RunLoop::isMain() propertly (sic) return true in [in affected iOS apps] (while WTF::isMainThread() returns false)." It would be good to understand why WTF::isMainThread() can return the wrong result in iOS WebKit2 and fix it. If it is not feasible to fix it and we know that RunLoop:Main() always returns the correct answer (to the question whether the currently running thread is the main thread) then we should substitute RunLoop:Main() for all uses of WTF::isMainThread().
Comment 1 Radar WebKit Bug Importer 2017-06-22 16:47:57 PDT
<rdar://problem/32936527>
Comment 2 Chris Dumez 2017-06-22 16:53:16 PDT
The apps that were broken used both WK2 and WK1 I believe. I have not looked in details yet but my guess is that WTF::isMainThread() gets confused by the fact that there is a WebThread in the UIProcess?
Comment 3 Chris Dumez 2017-06-22 18:48:52 PDT
Similar change made by Tim in:
https://bugs.webkit.org/show_bug.cgi?id=134900
Comment 4 Chris Dumez 2017-06-22 18:49:48 PDT
And by Enrica in:
https://bugs.webkit.org/show_bug.cgi?id=129135
Comment 5 Chris Dumez 2017-06-22 18:55:16 PDT
Created attachment 313683 [details]
Patch
Comment 6 Simon Fraser (smfr) 2017-06-22 18:55:22 PDT
Can we rename isMainThread to avoid this confusion?
Comment 7 Chris Dumez 2017-06-22 18:58:02 PDT
(In reply to Simon Fraser (smfr) from comment #6)
> Can we rename isMainThread to avoid this confusion?

Maybe. Although I'd rather do this in a separate patch. Any naming proposal? IsMainThreadOrWebThread?

However, For non-Cocoa ports, isMainThread() does the right thing and is accurately named. The issue is only with iOS WebKit1 and the WebThread.
Comment 8 Chris Dumez 2017-06-22 19:00:19 PDT
Created attachment 313684 [details]
Patch
Comment 9 Chris Dumez 2017-06-22 19:04:41 PDT
We recently had similar issues with using WebCore::Timer in the UIProcess. As a result, we'd want to add an assertion in the WebCore::Timer to make sure it is not called from the UIProcess. The issue is that we'd need a way to detect this accurately (and not break WebKit1 code running in the UIProcess).

Ideally, we'd add a similar assertion in WTF::isMainThread() (or make WTF::isMainThread() work reliably).
Comment 10 Chris Dumez 2017-06-22 19:05:52 PDT
(In reply to Chris Dumez from comment #9)
> We recently had similar issues with using WebCore::Timer in the UIProcess.
> As a result, we'd want to add an assertion in the WebCore::Timer to make
> sure it is not called from the UIProcess. The issue is that we'd need a way
> to detect this accurately (and not break WebKit1 code running in the
> UIProcess).
> 
> Ideally, we'd add a similar assertion in WTF::isMainThread() (or make
> WTF::isMainThread() work reliably).

Note that this patch helps but does not protect again people using WTF::isMainThread() is the UIProcess again. It also doesn't take care of code that is in WebCore and potentially called from the UIProcess.
Comment 11 Chris Dumez 2017-06-22 19:27:15 PDT
Created attachment 313686 [details]
Patch
Comment 12 Brent Fulgham 2017-06-23 13:47:57 PDT
Comment on attachment 313686 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=313686&action=review

Looks good. I was about to make this mistake in another patch! r=me.

> Source/WebKit2/Shared/CoordinatedGraphics/CoordinatedGraphicsScene.cpp:592
> +    bool calledOnMainThread = WTF::RunLoop::isMain();

Do we need WTF:: here? We don't use it elsewhere.
Comment 13 Chris Dumez 2017-06-23 13:50:02 PDT
Created attachment 313744 [details]
Patch
Comment 14 WebKit Commit Bot 2017-06-23 14:18:31 PDT
Comment on attachment 313744 [details]
Patch

Clearing flags on attachment: 313744

Committed r218763: <http://trac.webkit.org/changeset/218763>
Comment 15 WebKit Commit Bot 2017-06-23 14:18:33 PDT
All reviewed patches have been landed.  Closing bug.