Bug 204524 - [iOS] Copy assertions before iterating over them in _notifyAssertionsOfImminentSuspension
Summary: [iOS] Copy assertions before iterating over them in _notifyAssertionsOfImmine...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebKit2 (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Chris Dumez
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2019-11-22 10:33 PST by Chris Dumez
Modified: 2019-11-22 15:50 PST (History)
6 users (show)

See Also:


Attachments
Patch (2.12 KB, patch)
2019-11-22 10:35 PST, Chris Dumez
ap: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Chris Dumez 2019-11-22 10:33:06 PST
Copy assertions before iterating over them in _notifyAssertionsOfImminentSuspension.
Comment 1 Chris Dumez 2019-11-22 10:33:23 PST
<rdar://problem/57265830>
Comment 2 Chris Dumez 2019-11-22 10:35:08 PST
Created attachment 384166 [details]
Patch
Comment 3 Alexey Proskuryakov 2019-11-22 15:16:38 PST
Comment on attachment 384166 [details]
Patch

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

> Source/WebKit/ChangeLog:13
> +        them. It is common for process assertions to get released when uiAssertionWillExpireImminently()
> +        gets called, which would remove them from the _assertionsNeedingBackgroundTask vector we were
> +        iterating on.

Is it possible to assertions to be added to the vector while iterating?
Comment 4 Chris Dumez 2019-11-22 15:20:45 PST
(In reply to Alexey Proskuryakov from comment #3)
> Comment on attachment 384166 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=384166&action=review
> 
> > Source/WebKit/ChangeLog:13
> > +        them. It is common for process assertions to get released when uiAssertionWillExpireImminently()
> > +        gets called, which would remove them from the _assertionsNeedingBackgroundTask vector we were
> > +        iterating on.
> 
> Is it possible to assertions to be added to the vector while iterating?

Not as far as I know, we're telling the clients that their assertion has expired and they're supposed to abort whatever they're doing (and release their assertion).
The "release their assertion" is logic I added recently, which is why this regressed.
Comment 5 Alexey Proskuryakov 2019-11-22 15:39:49 PST
Comment on attachment 384166 [details]
Patch

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

> Source/WebKit/UIProcess/ios/ProcessAssertionIOS.mm:115
> +    Vector<WeakPtr<ProcessAndUIAssertion>> assertionsNeedingBackgroundTask = WTF::map(_assertionsNeedingBackgroundTask, [](auto* assertion) {

Seems worth explaining in a comment why we don't expect anything to be added to _assertionsNeedingBackgroundTask while iterating - or maybe even ASSERT at the end that there isn't anything new.
Comment 6 Chris Dumez 2019-11-22 15:50:31 PST
Committed r252811: <https://trac.webkit.org/changeset/252811>