Bug 159331

Summary: Deadlock inside -[WebCoreNSURLSession dealloc]
Product: WebKit Reporter: Jer Noble <jer.noble>
Component: New BugsAssignee: Jer Noble <jer.noble>
Status: RESOLVED FIXED    
Severity: Normal CC: benjamin, cdumez, cmarcelo, commit-queue, ggaren, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
Patch none

Description Jer Noble 2016-06-30 23:14:01 PDT
SPIN inside -[WebCoreNSURLSession dealloc]
Comment 1 Jer Noble 2016-06-30 23:21:51 PDT
<rdar://problem/27122716>
Comment 2 Jer Noble 2016-06-30 23:25:41 PDT
Created attachment 282513 [details]
Patch
Comment 3 Alex Christensen 2016-07-01 00:20:20 PDT
Comment on attachment 282513 [details]
Patch

Alternatively, you could just move the declaration of function inside the while loop scope (but not in the lock scope).
Comment 4 Jer Noble 2016-07-01 08:38:03 PDT
(In reply to comment #3)
> Comment on attachment 282513 [details]
> Patch
> 
> Alternatively, you could just move the declaration of function inside the
> while loop scope (but not in the lock scope).


I considered that, but thought this way would be slightly less expensive (no call to the constructor and destructor), as well as is more explicit about what's going on.
Comment 5 WebKit Commit Bot 2016-07-01 08:41:05 PDT
Comment on attachment 282513 [details]
Patch

Clearing flags on attachment: 282513

Committed r202736: <http://trac.webkit.org/changeset/202736>
Comment 6 WebKit Commit Bot 2016-07-01 08:41:10 PDT
All reviewed patches have been landed.  Closing bug.
Comment 7 Geoffrey Garen 2016-07-01 09:30:18 PDT
Comment on attachment 282513 [details]
Patch

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

> Source/WTF/wtf/MainThread.cpp:137
> +        // Clearing the function can have side effects, so do so outside of the lock above.
> +        function = nullptr;

Can we just move the declaration of function inside the loop? That's the C++ way to specify the semantics you want: Don't allow this value to outlive this loop body.
Comment 8 Geoffrey Garen 2016-07-01 09:34:54 PDT
> > Alternatively, you could just move the declaration of function inside the
> > while loop scope (but not in the lock scope).
> 
> 
> I considered that, but thought this way would be slightly less expensive (no
> call to the constructor and destructor), as well as is more explicit about
> what's going on.

There's no performance concern here. The empty constructor just assigns nullptr, which is exactly what you've done manually. Actually, there's a slight performance win, since it's much easier for the compiler to notice that nullptr is never observed, and eliminate the store entirely.
Comment 9 Jer Noble 2016-07-01 10:24:16 PDT
(In reply to comment #8)
> > > Alternatively, you could just move the declaration of function inside the
> > > while loop scope (but not in the lock scope).
> > 
> > 
> > I considered that, but thought this way would be slightly less expensive (no
> > call to the constructor and destructor), as well as is more explicit about
> > what's going on.
> 
> There's no performance concern here. The empty constructor just assigns
> nullptr, which is exactly what you've done manually. Actually, there's a
> slight performance win, since it's much easier for the compiler to notice
> that nullptr is never observed, and eliminate the store entirely.

Okay, sure.  I'll post a follow up.