RESOLVED FIXED 201249
CompletionHandler default constructor does not initialize `m_wasConstructedOnMainThread`
https://bugs.webkit.org/show_bug.cgi?id=201249
Summary CompletionHandler default constructor does not initialize `m_wasConstructedOn...
Joseph Pecoraro
Reported 2019-08-28 16:26:12 PDT
CompletionHandler default constructor does not initialize `m_wasConstructedOnMainThread`
Attachments
Patch (1.46 KB, patch)
2019-08-28 16:51 PDT, Chris Dumez
no flags
Patch (1.56 KB, patch)
2019-08-29 08:24 PDT, Chris Dumez
no flags
Joseph Pecoraro
Comment 1 2019-08-28 16:28:43 PDT
Debug only member for assertions. I'm seeing assertions!
Chris Dumez
Comment 2 2019-08-28 16:31:06 PDT
(In reply to Joseph Pecoraro from comment #1) > Debug only member for assertions. I'm seeing assertions! Oh, I guess if somebody default-constructs a CompletionHandler and then later on assigns a lambda to it, and then calls the completion handler on the wrong thread. You found cases like this?
Joseph Pecoraro
Comment 3 2019-08-28 16:39:56 PDT
(In reply to Chris Dumez from comment #2) > (In reply to Joseph Pecoraro from comment #1) > > Debug only member for assertions. I'm seeing assertions! > > Oh, I guess if somebody default-constructs a CompletionHandler and then > later on assigns a lambda to it, and then calls the completion handler on > the wrong thread. You found cases like this? I'm adding code that is essentially like: CompletionHandler<void> handler; callOnMainThread([handler = WTFMove(handler)] mutable { handler(); }); And it is asserting. If I instead did: CompletionHandler<void> handler = []{}; callOnMainThread([handler = WTFMove(handler)] mutable { handler(); }); it is not asserting.
Chris Dumez
Comment 4 2019-08-28 16:41:09 PDT
(In reply to Joseph Pecoraro from comment #3) > (In reply to Chris Dumez from comment #2) > > (In reply to Joseph Pecoraro from comment #1) > > > Debug only member for assertions. I'm seeing assertions! > > > > Oh, I guess if somebody default-constructs a CompletionHandler and then > > later on assigns a lambda to it, and then calls the completion handler on > > the wrong thread. You found cases like this? > > I'm adding code that is essentially like: > > CompletionHandler<void> handler; > callOnMainThread([handler = WTFMove(handler)] mutable { > handler(); > }); > > And it is asserting. > > If I instead did: > > CompletionHandler<void> handler = []{}; > callOnMainThread([handler = WTFMove(handler)] mutable { > handler(); > }); > > it is not asserting. Yes, you're not allowed to call a default constructed Function or CompletionHandler, it is by design and has nothing to do with threading.
Joseph Pecoraro
Comment 5 2019-08-28 16:46:26 PDT
> Yes, you're not allowed to call a default constructed Function or > CompletionHandler, it is by design and has nothing to do with threading. Okay, sounds good. I can check if the completion handler was initialized (operator bool) in these cases. Note that `CompletionHandlerCallingScope` does just that. Thanks!
Chris Dumez
Comment 6 2019-08-28 16:47:39 PDT
Why are we closing this. We should probably still fix the bug where m_wasConstructedOnMainThread is not initialized.
Chris Dumez
Comment 7 2019-08-28 16:47:57 PDT
Will fix.
Joseph Pecoraro
Comment 8 2019-08-28 16:49:11 PDT
Fair enough, but if we fix this won't it just assert next that the function is not callable next. So some assertion will happen.
Chris Dumez
Comment 9 2019-08-28 16:50:30 PDT
(In reply to Joseph Pecoraro from comment #8) > Fair enough, but if we fix this won't it just assert next that the function > is not callable next. So some assertion will happen. Right, but still seems wrong to have an uninitialized data member.
Chris Dumez
Comment 10 2019-08-28 16:51:06 PDT
Joseph Pecoraro
Comment 11 2019-08-28 16:52:02 PDT
Comment on attachment 377511 [details] Patch r=me
Joseph Pecoraro
Comment 12 2019-08-28 16:52:32 PDT
> Right, but still seems wrong to have an uninitialized data member. Sounds good!
Alex Christensen
Comment 13 2019-08-28 16:54:09 PDT
Comment on attachment 377511 [details] Patch Why not just put this in an initializer list and keep the =default?
Chris Dumez
Comment 14 2019-08-28 16:56:53 PDT
(In reply to Alex Christensen from comment #13) > Comment on attachment 377511 [details] > Patch > > Why not just put this in an initializer list and keep the =default? Oh, I can try this.
Chris Dumez
Comment 15 2019-08-29 08:24:06 PDT
WebKit Commit Bot
Comment 16 2019-08-29 10:11:12 PDT
Comment on attachment 377587 [details] Patch Clearing flags on attachment: 377587 Committed r249280: <https://trac.webkit.org/changeset/249280>
WebKit Commit Bot
Comment 17 2019-08-29 10:11:13 PDT
All reviewed patches have been landed. Closing bug.
Radar WebKit Bug Importer
Comment 18 2019-08-29 10:12:27 PDT
Note You need to log in before you can comment on or make changes to this bug.