Bug 211207 - REGRESSION(r260791) Network process fails to suspend promptly
Summary: REGRESSION(r260791) Network process fails to suspend promptly
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: 211080
  Show dependency treegraph
 
Reported: 2020-04-29 14:33 PDT by Chris Dumez
Modified: 2020-06-02 16:21 PDT (History)
4 users (show)

See Also:


Attachments
Patch (7.22 KB, patch)
2020-04-29 15:35 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (7.27 KB, patch)
2020-04-29 16:00 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (14.71 KB, patch)
2020-04-29 16:59 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
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].