Bug 185134

Summary: Fix bad use of RunLoop::main().dispatch() in MessagePort::dispatchMessages()
Product: WebKit Reporter: Chris Dumez <cdumez>
Component: DOMAssignee: Chris Dumez <cdumez>
Status: RESOLVED FIXED    
Severity: Normal CC: ap, beidson, cdumez, commit-queue, dbates, esprehn+autocc, ews-watchlist, ggaren, kangil.han, webkit-bug-importer, youennf
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
See Also: https://bugs.webkit.org/show_bug.cgi?id=185073
Attachments:
Description Flags
Patch none

Chris Dumez
Reported 2018-04-30 09:44:44 PDT
Fix bad use of RunLoop::main().dispatch() in MessagePort::dispatchMessages(). This code runs on iOS WebKitLegacy and it is therefore unsafe to use RunLoop::main() here. We want to use callOnMainThread() instead to run code on the WebThread.
Attachments
Patch (1.78 KB, patch)
2018-04-30 09:45 PDT, Chris Dumez
no flags
Chris Dumez
Comment 1 2018-04-30 09:45:42 PDT
Geoffrey Garen
Comment 2 2018-04-30 09:51:44 PDT
Comment on attachment 339116 [details] Patch r=me
Daniel Bates
Comment 3 2018-04-30 10:59:25 PDT
Comment on attachment 339116 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=339116&action=review > Source/WebCore/dom/MessagePort.cpp:-287 > - RunLoop::main().dispatch([completionCallback = WTFMove(completionCallback)] { Is there anything that we can do to prevent this kind of mistake from the getgo? It seems to be repeatedly made.
Chris Dumez
Comment 4 2018-04-30 11:50:35 PDT
(In reply to Daniel Bates from comment #3) > Comment on attachment 339116 [details] > Patch > > View in context: > https://bugs.webkit.org/attachment.cgi?id=339116&action=review > > > Source/WebCore/dom/MessagePort.cpp:-287 > > - RunLoop::main().dispatch([completionCallback = WTFMove(completionCallback)] { > > Is there anything that we can do to prevent this kind of mistake from the > getgo? It seems to be repeatedly made. I agree it would be nice. Maybe we could introduce a rule enforced by the style checker that RunLoop::main().dispatch() should never be used in WebCore? I don't have a better idea at the moment.
WebKit Commit Bot
Comment 5 2018-04-30 12:13:38 PDT
Comment on attachment 339116 [details] Patch Clearing flags on attachment: 339116 Committed r231161: <https://trac.webkit.org/changeset/231161>
WebKit Commit Bot
Comment 6 2018-04-30 12:13:40 PDT
All reviewed patches have been landed. Closing bug.
Radar WebKit Bug Importer
Comment 7 2018-04-30 12:14:31 PDT
Daniel Bates
Comment 8 2018-04-30 14:16:25 PDT
(In reply to Chris Dumez from comment #4) > (In reply to Daniel Bates from comment #3) > > Comment on attachment 339116 [details] > > Patch > > > > View in context: > > https://bugs.webkit.org/attachment.cgi?id=339116&action=review > > > > > Source/WebCore/dom/MessagePort.cpp:-287 > > > - RunLoop::main().dispatch([completionCallback = WTFMove(completionCallback)] { > > > > Is there anything that we can do to prevent this kind of mistake from the > > getgo? It seems to be repeatedly made. > > I agree it would be nice. Maybe we could introduce a rule enforced by the > style checker that RunLoop::main().dispatch() should never be used in > WebCore? I don't have a better idea at the moment. Notice that the WebThread code is guarded by USE(WEB_THREAD) and we only enable this feature on iOS. Can we take advantage of this together with a static_assert() to cause a compile-time failure with a helpful message whenever someone makes use unsafe or potentially unsafe RunLoop functionality, including RunLoop::main().dispatch()?
Chris Dumez
Comment 9 2018-04-30 16:28:10 PDT
(In reply to Daniel Bates from comment #8) > (In reply to Chris Dumez from comment #4) > > (In reply to Daniel Bates from comment #3) > > > Comment on attachment 339116 [details] > > > Patch > > > > > > View in context: > > > https://bugs.webkit.org/attachment.cgi?id=339116&action=review > > > > > > > Source/WebCore/dom/MessagePort.cpp:-287 > > > > - RunLoop::main().dispatch([completionCallback = WTFMove(completionCallback)] { > > > > > > Is there anything that we can do to prevent this kind of mistake from the > > > getgo? It seems to be repeatedly made. > > > > I agree it would be nice. Maybe we could introduce a rule enforced by the > > style checker that RunLoop::main().dispatch() should never be used in > > WebCore? I don't have a better idea at the moment. > > Notice that the WebThread code is guarded by USE(WEB_THREAD) and we only > enable this feature on iOS. Can we take advantage of this together with a > static_assert() to cause a compile-time failure with a helpful message > whenever someone makes use unsafe or potentially unsafe RunLoop > functionality, including RunLoop::main().dispatch()? RunLoop is in WTF and USE_WEB_THREAD is set to 1 when building WTF on iOS. Therefore, the static_assert(!USE_WEB_THREAD, "") would cause a build error on iOS, even though it is perfectly fine to call RunLoop::main().dispatch() from iOS WebKit2 code. I might be missing something.
Note You need to log in before you can comment on or make changes to this bug.