Bug 211207

Summary: REGRESSION(r260791) Network process fails to suspend promptly
Product: WebKit Reporter: Chris Dumez <cdumez>
Component: WebKit2Assignee: Chris Dumez <cdumez>
Status: RESOLVED FIXED    
Severity: Normal CC: achristensen, darin, ggaren, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
See Also: https://bugs.webkit.org/show_bug.cgi?id=212608
Bug Depends on:    
Bug Blocks: 211080    
Attachments:
Description Flags
Patch
none
Patch
none
Patch none

Description Chris Dumez 2020-04-29 14:33:40 PDT
Network process fails to suspend promptly because NetworkProcess::prepareToSuspend() does not call its completion handler.

This issue is with this code and was caused by using the same WorkQueue for all ITP stores:
"""
    forEachNetworkSession([&callbackAggregator](auto& networkSession) {
        if (auto* resourceLoadStatistics = networkSession.resourceLoadStatistics()) {
            if (!resourceLoadStatistics->isEphemeral()) {
                WTFLogAlways("CHRIS: resourceLoadStatistics::BEGIN");
                resourceLoadStatistics->suspend([callbackAggregator] { WTFLogAlways("CHRIS: resourceLoadStatistics::END"); });
            }
        }
    });
"""

On first loop iteration, resourceLoadStatistics->suspend() hangs/suspends the WorkQueue so every follow-up iteration will hang when calling resourceLoadStatistics->suspend().
Comment 1 Chris Dumez 2020-04-29 15:03:42 PDT
Will try a static suspend() for the static WorkQueue, instead of suspending each ITP store individually.
Comment 2 Radar WebKit Bug Importer 2020-04-29 15:26:07 PDT
<rdar://problem/62620454>
Comment 3 Chris Dumez 2020-04-29 15:35:49 PDT
Created attachment 398002 [details]
Patch
Comment 4 Chris Dumez 2020-04-29 15:36:37 PDT
Comment on attachment 398002 [details]
Patch

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

> Source/WebKit/ChangeLog:12
> +

Trying to write an API test for this. For now, I validated this manually.
Comment 5 Alex Christensen 2020-04-29 15:40:21 PDT
Comment on attachment 398002 [details]
Patch

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

> Source/WebKit/NetworkProcess/Classifier/WebResourceLoadStatisticsStore.cpp:-1385
> -    ASSERT(RunLoop::isMain() && !isEphemeral());

Why not keep the RunLoop::isMain() assertion?
Comment 6 Geoffrey Garen 2020-04-29 15:41:38 PDT
Why not just call the completion handler, if that was the bug?
Comment 7 Geoffrey Garen 2020-04-29 15:42:12 PDT
Comment on attachment 398002 [details]
Patch

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

> Source/WebKit/NetworkProcess/Classifier/WebResourceLoadStatisticsStore.cpp:67
> +WebResourceLoadStatisticsStore::State WebResourceLoadStatisticsStore::suspendedState { WebResourceLoadStatisticsStore::State::Running };
> +Lock WebResourceLoadStatisticsStore::suspendedStateLock;
> +Condition WebResourceLoadStatisticsStore::suspendedStateChangeCondition;

Do these need to be globals instead of data members?
Comment 8 Alex Christensen 2020-04-29 15:43:35 PDT
They're static, so just as global as sharedStatisticsQueue
Comment 9 Chris Dumez 2020-04-29 16:00:19 PDT
Created attachment 398003 [details]
Patch
Comment 10 Chris Dumez 2020-04-29 16:01:43 PDT
(In reply to Geoffrey Garen from comment #7)
> Comment on attachment 398002 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=398002&action=review
> 
> > Source/WebKit/NetworkProcess/Classifier/WebResourceLoadStatisticsStore.cpp:67
> > +WebResourceLoadStatisticsStore::State WebResourceLoadStatisticsStore::suspendedState { WebResourceLoadStatisticsStore::State::Running };
> > +Lock WebResourceLoadStatisticsStore::suspendedStateLock;
> > +Condition WebResourceLoadStatisticsStore::suspendedStateChangeCondition;
> 
> Do these need to be globals instead of data members?

Could you clarify? They are global in that they are static. Would you like me to move those statics to the cpp?
Comment 11 Chris Dumez 2020-04-29 16:59:27 PDT
Created attachment 398010 [details]
Patch
Comment 12 Chris Dumez 2020-04-29 16:59:42 PDT
I added an API test.
Comment 13 EWS 2020-04-29 17:50:07 PDT
Committed r260928: <https://trac.webkit.org/changeset/260928>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 398010 [details].