Bug 227160

Summary: Functions dispatched to WorkQueue are sometimes destroyed in the calling thread due to block refcounting
Product: WebKit Reporter: Kimmo Kinnunen <kkinnunen>
Component: PlatformAssignee: Kimmo Kinnunen <kkinnunen>
Status: RESOLVED FIXED    
Severity: Normal CC: benjamin, cdumez, cmarcelo, eric.carlson, ews-watchlist, glenn, jer.noble, koivisto, philipj, sergio, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Local Build   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
Patch
none
Patch for landing
none
Patch for landing none

Description Kimmo Kinnunen 2021-06-18 01:00:07 PDT
Functions dispatched to WorkQueue are sometimes destroyed in the calling thread due to block refcounting

A lot of dispatched lambdas are written with the expectation that the destruction of the lambda is done in the called  thread.

See discussion for r270876 as a example where time was spent debugging this. 

See git grep "dispatch(.*WTFMove.*{.*}" for subset of call sites that expect the WorkQueue to behave in different way.
Comment 1 Kimmo Kinnunen 2021-06-18 01:30:32 PDT
Created attachment 431761 [details]
Patch
Comment 2 Antti Koivisto 2021-06-18 02:54:11 PDT
Comment on attachment 431761 [details]
Patch

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

> Source/WTF/wtf/cocoa/WorkQueueCocoa.cpp:35
> +namespace {
> +struct DispatchWorkItem {

Could use an empty line here.

> Source/WTF/wtf/cocoa/WorkQueueCocoa.cpp:51
> +
> +

Extra empty line here.
Comment 3 Kimmo Kinnunen 2021-06-18 03:43:43 PDT
Created attachment 431766 [details]
Patch for landing
Comment 4 Kimmo Kinnunen 2021-06-21 01:12:37 PDT
Created attachment 431836 [details]
Patch for landing
Comment 5 EWS 2021-06-22 06:25:13 PDT
Committed r279115 (239032@main): <https://commits.webkit.org/239032@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 431836 [details].
Comment 6 Radar WebKit Bug Importer 2021-06-22 06:26:17 PDT
<rdar://problem/79611008>