Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(690)

Issue 374583002: Replace CallClosureTask::create(bind()) with createCrossThreadTask() (Closed)

Created:
6 years, 5 months ago by hiroshige
Modified:
6 years, 5 months ago
CC:
eae+blinkwatch, tommyw+watchlist_chromium.org, falken, dglazkov+blink, kinuko+worker_chromium.org, horo+watch_chromium.org, rwlbuis, oilpan-reviews
Base URL:
https://chromium.googlesource.com/chromium/blink.git@master
Project:
blink
Visibility:
Public.

Description

Replace CallClosureTask::create(bind()) with createCrossThreadTask() Background: The code pattern of postTask(CallClosureTask::create(bind(args))) is thread unsafe for posting tasks crossing threads, even if args are deep-copied, due to temporary objects (created as the return value of bind() and deep copy functions such as String::isolatedCopy()). Solution by this CL: Created createCrossThreadTask() and replaced all CallClosureTask::create(bind()) with createCrossThreadTask(). createCrossThreadTask calls bind and does deep copy (if necessary) by CrossThreadCopier inside createCrossThreadTask, like createCallbackTask. This is safer for cross-thread task posting because all temporary objects are created inside createCrossThreadTask (not in its caller), and thus destroyed before returning from createCrossThreadTask (i.e. before calling postTask). Removed postTask() and postInspectorTask() that accepts Closure& (i.e. return value of bind()). BUG=390851 BUG=390174 Committed: https://src.chromium.org/viewvc/blink?view=rev&revision=177815

Patch Set 1 #

Total comments: 6

Patch Set 2 : Modified comments #

Patch Set 3 : Move createCallClosureTask to CrossThreadTask.h #

Total comments: 12

Patch Set 4 : Rebase, rename to createCrossThreadTask, and so #

Total comments: 4

Patch Set 5 : #

Patch Set 6 : #

Unified diffs Side-by-side diffs Delta from patch set Stats (+271 lines, -53 lines) Patch
M Source/core/dom/CrossThreadTask.h View 1 2 3 4 1 chunk +239 lines, -0 lines 0 comments Download
M Source/core/dom/Document.h View 1 2 3 1 chunk +1 line, -1 line 0 comments Download
M Source/core/dom/Document.cpp View 1 2 3 1 chunk +2 lines, -2 lines 0 comments Download
M Source/core/dom/ExecutionContext.h View 1 chunk +0 lines, -1 line 0 comments Download
M Source/core/dom/ExecutionContext.cpp View 1 chunk +0 lines, -7 lines 0 comments Download
M Source/core/dom/ExecutionContextTask.h View 1 2 3 4 5 1 chunk +2 lines, -0 lines 0 comments Download
M Source/core/dom/MessagePort.cpp View 1 2 3 2 chunks +2 lines, -1 line 0 comments Download
M Source/core/page/NetworkStateNotifier.cpp View 1 2 3 2 chunks +2 lines, -1 line 0 comments Download
M Source/core/workers/WorkerObjectProxy.cpp View 1 2 3 4 chunks +9 lines, -8 lines 0 comments Download
M Source/modules/mediastream/MediaStreamTrackSourcesRequestImpl.cpp View 1 2 3 2 chunks +2 lines, -1 line 0 comments Download
M Source/modules/webdatabase/SQLTransactionClient.cpp View 1 2 3 2 chunks +2 lines, -1 line 0 comments Download
M Source/modules/websockets/WorkerThreadableWebSocketChannel.cpp View 1 2 3 7 chunks +8 lines, -29 lines 0 comments Download
M Source/web/ServiceWorkerGlobalScopeProxy.cpp View 1 2 3 2 chunks +2 lines, -1 line 0 comments Download

Messages

Total messages: 33 (0 generated)
hiroshige
6 years, 5 months ago (2014-07-07 08:34:47 UTC) #1
tyoshino (SeeGerritForStatus)
Please include the subject in the CL description. When the CL is committed, only the ...
6 years, 5 months ago (2014-07-07 09:35:17 UTC) #2
tyoshino (SeeGerritForStatus)
On 2014/07/07 09:35:17, tyoshino wrote: > Please include the subject in the CL description. When ...
6 years, 5 months ago (2014-07-07 09:37:37 UTC) #3
tyoshino (SeeGerritForStatus)
https://codereview.chromium.org/374583002/diff/1/Source/core/dom/ExecutionContextTask.h File Source/core/dom/ExecutionContextTask.h (right): https://codereview.chromium.org/374583002/diff/1/Source/core/dom/ExecutionContextTask.h#newcode65 Source/core/dom/ExecutionContextTask.h:65: // templates for member function of class C + ...
6 years, 5 months ago (2014-07-07 09:48:10 UTC) #4
hiroshige
Thank you for reviewing. I modified the comments in the code and also modified the ...
6 years, 5 months ago (2014-07-07 11:31:27 UTC) #5
tkent
My understanding is that WTF::bind() is unusable for cross-thread posting by design, and we should ...
6 years, 5 months ago (2014-07-08 01:32:02 UTC) #6
tyoshino (SeeGerritForStatus)
On 2014/07/08 01:32:02, tkent wrote: > My understanding is that WTF::bind() is unusable for cross-thread ...
6 years, 5 months ago (2014-07-08 03:54:38 UTC) #7
tkent
Probably I thought WTF::bind was unusable because it didn't apply CrossThreadCopier automatically. If so, - ...
6 years, 5 months ago (2014-07-08 04:19:59 UTC) #8
hiroshige
On 2014/07/08 04:19:59, tkent wrote: > Probably I thought WTF::bind was unusable because it didn't ...
6 years, 5 months ago (2014-07-09 09:19:32 UTC) #9
tkent
Please wrap the CL description in 80 columns. https://codereview.chromium.org/374583002/diff/40001/Source/core/dom/CrossThreadTask.h File Source/core/dom/CrossThreadTask.h (right): https://codereview.chromium.org/374583002/diff/40001/Source/core/dom/CrossThreadTask.h#newcode481 Source/core/dom/CrossThreadTask.h:481: // ...
6 years, 5 months ago (2014-07-10 03:36:14 UTC) #10
hiroshige
> Please wrap the CL description in 80 columns. Done. https://codereview.chromium.org/374583002/diff/40001/Source/core/dom/CrossThreadTask.h File Source/core/dom/CrossThreadTask.h (right): https://codereview.chromium.org/374583002/diff/40001/Source/core/dom/CrossThreadTask.h#newcode481 ...
6 years, 5 months ago (2014-07-10 04:39:56 UTC) #11
tyoshino (SeeGerritForStatus)
https://codereview.chromium.org/374583002/diff/40001/Source/core/dom/CrossThreadTask.h File Source/core/dom/CrossThreadTask.h (right): https://codereview.chromium.org/374583002/diff/40001/Source/core/dom/CrossThreadTask.h#newcode481 Source/core/dom/CrossThreadTask.h:481: // createCallClosureTask(...) is similar to but safer than On ...
6 years, 5 months ago (2014-07-10 04:50:04 UTC) #12
yhirano
https://codereview.chromium.org/374583002/diff/40001/Source/core/dom/ExecutionContextTask.h File Source/core/dom/ExecutionContextTask.h (right): https://codereview.chromium.org/374583002/diff/40001/Source/core/dom/ExecutionContextTask.h#newcode56 Source/core/dom/ExecutionContextTask.h:56: // Do not use create other than in createCallClosureTask. ...
6 years, 5 months ago (2014-07-10 04:55:42 UTC) #13
tkent
https://codereview.chromium.org/374583002/diff/40001/Source/core/dom/CrossThreadTask.h File Source/core/dom/CrossThreadTask.h (right): https://codereview.chromium.org/374583002/diff/40001/Source/core/dom/CrossThreadTask.h#newcode481 Source/core/dom/CrossThreadTask.h:481: // createCallClosureTask(...) is similar to but safer than On ...
6 years, 5 months ago (2014-07-10 05:06:23 UTC) #14
hiroshige
https://codereview.chromium.org/374583002/diff/40001/Source/core/dom/CrossThreadTask.h File Source/core/dom/CrossThreadTask.h (right): https://codereview.chromium.org/374583002/diff/40001/Source/core/dom/CrossThreadTask.h#newcode481 Source/core/dom/CrossThreadTask.h:481: // createCallClosureTask(...) is similar to but safer than > ...
6 years, 5 months ago (2014-07-10 07:16:32 UTC) #15
tyoshino (SeeGerritForStatus)
https://codereview.chromium.org/374583002/diff/60001/Source/core/dom/CrossThreadTask.h File Source/core/dom/CrossThreadTask.h (right): https://codereview.chromium.org/374583002/diff/60001/Source/core/dom/CrossThreadTask.h#newcode510 Source/core/dom/CrossThreadTask.h:510: template<typename C, typename P2, typename A2> Start from P1 ...
6 years, 5 months ago (2014-07-10 07:31:46 UTC) #16
tkent
lgtm Please replace createCallClosureTask in the CL description with createCrossThreadTask https://codereview.chromium.org/374583002/diff/60001/Source/core/dom/ExecutionContextTask.h File Source/core/dom/ExecutionContextTask.h (right): https://codereview.chromium.org/374583002/diff/60001/Source/core/dom/ExecutionContextTask.h#newcode54 ...
6 years, 5 months ago (2014-07-10 07:55:13 UTC) #17
hiroshige
https://codereview.chromium.org/374583002/diff/60001/Source/core/dom/CrossThreadTask.h File Source/core/dom/CrossThreadTask.h (right): https://codereview.chromium.org/374583002/diff/60001/Source/core/dom/CrossThreadTask.h#newcode510 Source/core/dom/CrossThreadTask.h:510: template<typename C, typename P2, typename A2> On 2014/07/10 07:31:46, ...
6 years, 5 months ago (2014-07-10 08:14:36 UTC) #18
tyoshino (SeeGerritForStatus)
lgtm
6 years, 5 months ago (2014-07-10 08:27:04 UTC) #19
tyoshino (SeeGerritForStatus)
The CQ bit was checked by tyoshino@chromium.org
6 years, 5 months ago (2014-07-10 08:27:36 UTC) #20
commit-bot: I haz the power
CQ is trying da patch. Follow status at https://chromium-status.appspot.com/cq/hiroshige@chromium.org/374583002/100001
6 years, 5 months ago (2014-07-10 08:28:08 UTC) #21
commit-bot: I haz the power
FYI, CQ is re-trying this CL (attempt #1). The failing builders are: linux_blink_dbg on tryserver.blink ...
6 years, 5 months ago (2014-07-10 09:35:02 UTC) #22
commit-bot: I haz the power
Change committed as 177815
6 years, 5 months ago (2014-07-10 10:40:04 UTC) #23
sof
Looks like this broke Oilpan compilation, http://build.chromium.org/p/chromium.webkit/builders/WebKit%20Linux%20Oilpan/builds/8758
6 years, 5 months ago (2014-07-10 11:11:59 UTC) #24
haraken
On 2014/07/10 11:11:59, sof wrote: > Looks like this broke Oilpan compilation, > > > ...
6 years, 5 months ago (2014-07-10 11:31:58 UTC) #25
hiroshige
On 2014/07/10 11:31:58, haraken wrote: > On 2014/07/10 11:11:59, sof wrote: > > Looks like ...
6 years, 5 months ago (2014-07-10 11:50:36 UTC) #26
haraken
On 2014/07/10 11:50:36, hiroshige wrote: > On 2014/07/10 11:31:58, haraken wrote: > > On 2014/07/10 ...
6 years, 5 months ago (2014-07-10 11:57:09 UTC) #27
sof
On 2014/07/10 11:57:09, haraken wrote: > On 2014/07/10 11:50:36, hiroshige wrote: > > On 2014/07/10 ...
6 years, 5 months ago (2014-07-10 11:59:33 UTC) #28
haraken
On 2014/07/10 11:59:33, sof wrote: > On 2014/07/10 11:57:09, haraken wrote: > > On 2014/07/10 ...
6 years, 5 months ago (2014-07-10 12:02:18 UTC) #29
hiroshige
On 2014/07/10 12:02:18, haraken wrote: > On 2014/07/10 11:59:33, sof wrote: > > On 2014/07/10 ...
6 years, 5 months ago (2014-07-10 12:06:14 UTC) #30
sof
On 2014/07/10 12:06:14, hiroshige wrote: > On 2014/07/10 12:02:18, haraken wrote: > > On 2014/07/10 ...
6 years, 5 months ago (2014-07-10 12:10:05 UTC) #31
haraken
On 2014/07/10 12:10:05, sof wrote: > On 2014/07/10 12:06:14, hiroshige wrote: > > On 2014/07/10 ...
6 years, 5 months ago (2014-07-10 12:16:55 UTC) #32
hiroshige
6 years, 5 months ago (2014-07-10 13:11:34 UTC) #33
Message was sent while issue was closed.
On 2014/07/10 12:16:55, haraken wrote:
> On 2014/07/10 12:10:05, sof wrote:
> > On 2014/07/10 12:06:14, hiroshige wrote:
> > > On 2014/07/10 12:02:18, haraken wrote:
> > > > On 2014/07/10 11:59:33, sof wrote:
> > > > > On 2014/07/10 11:57:09, haraken wrote:
> > > > > > On 2014/07/10 11:50:36, hiroshige wrote:
> > > > > > > On 2014/07/10 11:31:58, haraken wrote:
> > > > > > > > On 2014/07/10 11:11:59, sof wrote:
> > > > > > > > > Looks like this broke Oilpan compilation,
> > > > > > > > > 
> > > > > > > > > 
> > > > > > > > >
> > > > > > > >
> > > > > > >
> > > > > >
> > > > >
> > > >
> > >
> >
>
http://build.chromium.org/p/chromium.webkit/builders/WebKit%20Linux%20Oilpan/...
> > > > > > > > 
> > > > > > > > I'll handle this.
> > > > > > > 
> > > > > > > Thanks!
> > > > > > > 
> > > > > > > To call member function of class C (without
> AllowCrossThreadAccess()),
> > > my
> > > > > code
> > > > > > > only supports
> > > > > > > createCrossThreadTask(func,p,...) where func is a pointer to a
> member
> > > > > function
> > > > > > > of class C and
> > > > > > > p is pointer (C*) or WeakPtr<C>, but in Oilpan WeakMember or
RawPtr
> is
> > > > > passed
> > > > > > > instead.
> > > > > > > (Lines 503--641 in Source/core/dom/CrossThreadTask.h above)
> > > > > > > 
> > > > > > > A possible solution is to allow these code to catch everything
> (other
> > > than
> > > > > C*
> > > > > > > and WeakPtr<C>)
> > > > > > > to be passed without CrossThreadCopier if func is a pointer to a
> > member
> > > > > > > function,
> > > > > > > but not sure it is always correct.
> > > > > > 
> > > > > > Hmm, this is complicated.
> > > > > > 
> > > > > > I think we need to make the member function match:
> > > > > > 
> > > > > > template<typename T> struct CrossThreadCopierBase<false, false,
true,
> T>
> > {
> > > 
> > > > //
> > > > > > true means the object type is GarbageCollected.
> > > > > >    ...;
> > > > > > };
> > > > > > 
> > > > > > in order to use a correct CrossThreadCopier. So I added:
> > > > > > 
> > > > > > template<typename T> struct CrossThreadCopier : public
> > > > > > CrossThreadCopierBase<WTF::IsConvertibleToInteger<T>::value,   
> > > > > >         WTF::IsSubclassOfTemplate<typename WTF::RemoveTemplate<T,
> > > > > RefPtr>::Type,
> > > > > > ThreadSafeRefCounted>::value             
> > > > > >             || WTF::IsSubclassOfTemplate<typename
> > > > WTF::RemovePointer<T>::Type,
> > > > > > ThreadSafeRefCounted>::value               
> > > > > >             || WTF::IsSubclassOfTemplate<typename
> WTF::RemoveTemplate<T,
> > > > > > PassRefPtr>::Type, ThreadSafeRefCounted>::value, 
> > > > > >         WTF::IsSubclassOfTemplate<typename
> WTF::RemovePointer<T>::Type,
> > > > > > GarbageCollected>::value                          
> > > > > >             || WTF::IsSubclassOfTemplate<typename
> WTF::RemoveTemplate<T,
> > > > > > WeakMember>::Type, GarbageCollected>::value      
> > > > > >             || WTF::IsSubclassOfTemplate<typename
> WTF::RemoveTemplate<T,
> > > > > > RawPtr>::Type, GarbageCollected>::value,         
> > > > > >         T> {                                                        
 
>  
> >  
> > >  
> > > >  
> > > > >  
> > > > > >                                          
> > > > > >     };
> > > > > > 
> > > > > > but then I hit another error...
> > > > > > 
> > > > > > If you have some solution in mind, would you mind uploading a CL?
> > > > > 
> > > > > Here's my attempt -- https://codereview.chromium.org/388463002/
> > > > 
> > > > Thanks for the quick fix, looks correct to me!
> > > 
> > > Probably fixing CrossThreadCopier to pass these pointers is not correct,
> > because
> > > such fix also passes the pointers in the arguments (i.e. not pointer to
the
> > > object to be called), which can cause thread unsafe code.
> > > I'll create another CL soon.
> > 
> > Isn't that comment covered by the RawPtr FIXME in CrossThreadTask.h already?
> > i.e., the changes here seem no less unsafe than what's already in place. Or?
> 
> Yeah. I have to update the comment. The updated version of the comment is that
> 'FIXME: Using a RawPtr is not safe because the RawPtr does not keep anything
> alive while the ExecutionContextTask is holding the RawPtr. However, we cannot
> use Member nor Persistent for some complicated reason, so we cannot avoid
using
> a RawPtr. Thus the caller side must guarantee the safety of the RawPtr.'
> 
> hiroshige-san: What do you mean by "thread unsafe" specifically?

"Thread unsafe" I mentioned is to access RefCounted (or other reference counter
that is not thread safe) from multiple threads, and passing objects or pointers
that can cause such thread unsafe access to reference counters.

I was afraid that the change made CrossThreadCopier to pass pointers that is not
necessarily thread safe, but after looking at it carefully I found it seems safe
(only passes e.g. garbage collected ones).

Thanks for the fix!

Powered by Google App Engine
This is Rietveld 408576698