Bug 196307

Summary: [ Mac WK2 iOS Sim] Layout Test http/tests/resourceLoadStatistics/website-data-removal-for-site-navigated-to-with-link-decoration.html is a flaky failure
Product: WebKit Reporter: Shawn Roberts <sroberts>
Component: Tools / TestsAssignee: Sihui Liu <sihui_liu>
Status: RESOLVED FIXED    
Severity: Normal CC: achristensen, bfulgham, cdumez, commit-queue, dbates, ggaren, lforschler, rniwa, ryanhaddad, sihui_liu, webkit-bot-watchers-bugzilla, webkit-bug-importer, wilander
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
See Also: https://bugs.webkit.org/show_bug.cgi?id=196099
https://bugs.webkit.org/show_bug.cgi?id=199468
Bug Depends on: 199468    
Bug Blocks:    
Attachments:
Description Flags
Patch
none
Patch
none
Patch
none
Patch for landing none

Description Shawn Roberts 2019-03-27 11:25:27 PDT
The following layout test is failing on Mac WK2 Release and Debug, iOS Simulator Release and Debug

http/tests/resourceLoadStatistics/website-data-removal-for-site-navigated-to-with-link-decoration.html

Probable cause:

Test has been a flaky failure since it was created. However after the changes in https://trac.webkit.org/changeset/243348/webkit it became a more consistent failure.

On the bots as well as local testing, test will fail more consistently in full parallel or in debug mode. It will fail with the same diff in full parallel or with 1 child process.

Reproduced with:

run-webkit-tests http/tests/resourceLoadStatistics/website-data-removal-for-site-navigated-to-with-link-decoration.html --iterations 500 -f --ios-simulator --exit-after-n-failures=5 --no-retry
run-webkit-tests http/tests/resourceLoadStatistics/website-data-removal-for-site-navigated-to-with-link-decoration.html --iterations 500 --child-process 1 --ios-simulator --debug --exit-after-n-failures=5 --no-retry

Flakiness Dashboard:

https://webkit-test-results.webkit.org/dashboards/flakiness_dashboard.html#showAllRuns=true&tests=http%2Ftests%2FresourceLoadStatistics%2Fwebsite-data-removal-for-site-navigated-to-with-link-decoration.html

Diff:

--- /Volumes/Data/slave/ios-simulator-12-release-tests-wk2/build/layout-test-results/http/tests/resourceLoadStatistics/website-data-removal-for-site-navigated-to-with-link-decoration-expected.txt
+++ /Volumes/Data/slave/ios-simulator-12-release-tests-wk2/build/layout-test-results/http/tests/resourceLoadStatistics/website-data-removal-for-site-navigated-to-with-link-decoration-actual.txt
@@ -10,7 +10,7 @@
 After deletion: Client-side cookie exists.
 After deletion: Regular server-side cookie exists.
 
-After deletion: IDB entry does not exist.
+After deletion: IDB entry does exist.
 
 
 Resource load statistics:
@@ -32,4 +32,4 @@
         localhost
     gotLinkDecorationFromPrevalentResource: No    isPrevalentResource: No
     isVeryPrevalentResource: No
-    dataRecordsRemoved: 1
+    dataRecordsRemoved: 2
Comment 1 Radar WebKit Bug Importer 2019-03-27 11:28:08 PDT
<rdar://problem/49345360>
Comment 2 Shawn Roberts 2019-03-27 11:34:50 PDT
Marked as flaky in https://trac.webkit.org/changeset/243554/webkit while waiting for a fix.
Comment 3 Sihui Liu 2019-05-09 11:08:56 PDT
Created attachment 369498 [details]
Patch
Comment 4 Sihui Liu 2019-05-09 11:13:42 PDT
Created attachment 369499 [details]
Patch
Comment 5 Geoffrey Garen 2019-05-09 13:24:24 PDT
Comment on attachment 369499 [details]
Patch

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

> LayoutTests/http/tests/resourceLoadStatistics/website-data-removal-for-site-navigated-to-with-link-decoration.html:157
> +        setTimeout(checkWebsiteDataAndContinue, 1000);

It would be nice to avoid a fixed timeout, since those are sometimes flaky too.

One way to do that is to refactor checkWebsiteDataAndContinue to test for success, and reschedule itself upon failure, up to some limit like 10s. That way, passes can be fast, and only failures are slow.
Comment 6 Sihui Liu 2019-05-10 10:07:35 PDT
Created attachment 369559 [details]
Patch
Comment 7 Sihui Liu 2019-05-10 10:10:56 PDT
(In reply to Geoffrey Garen from comment #5)
> Comment on attachment 369499 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=369499&action=review
> 
> > LayoutTests/http/tests/resourceLoadStatistics/website-data-removal-for-site-navigated-to-with-link-decoration.html:157
> > +        setTimeout(checkWebsiteDataAndContinue, 1000);
> 
> It would be nice to avoid a fixed timeout, since those are sometimes flaky
> too.
> 
> One way to do that is to refactor checkWebsiteDataAndContinue to test for
> success, and reschedule itself upon failure, up to some limit like 10s. That
> way, passes can be fast, and only failures are slow.

It turns out IDB is not the last data type gets deleted. Even if IDB files are deleted, resource statistics may have not been updated, so we cannot use missing IDB database to decide whether the deletion of website data finishes.
Comment 8 Alex Christensen 2019-05-17 16:10:29 PDT
Comment on attachment 369559 [details]
Patch

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

> Source/WebKit/NetworkProcess/Classifier/WebResourceLoadStatisticsStore.cpp:618
> +        m_dumpResourceLoadStatisticsFunction = WTFMove(completionHandler);

Let's call this m_dumpResourceLoadStatisticsCompletionHandler, and assert that it's null before this sets it.
Comment 9 Sihui Liu 2019-05-20 09:35:03 PDT
Created attachment 370256 [details]
Patch for landing
Comment 10 WebKit Commit Bot 2019-05-20 10:14:39 PDT
Comment on attachment 370256 [details]
Patch for landing

Clearing flags on attachment: 370256

Committed r245517: <https://trac.webkit.org/changeset/245517>
Comment 11 WebKit Commit Bot 2019-05-20 10:14:41 PDT
All reviewed patches have been landed.  Closing bug.
Comment 12 Chris Dumez 2019-07-03 14:44:15 PDT
Comment on attachment 370256 [details]
Patch for landing

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

> Source/WebKit/NetworkProcess/Classifier/WebResourceLoadStatisticsStore.cpp:628
> +    ASSERT(!RunLoop::isMain());

This is not OK, the whole point of our abstraction is that WebResourceLoadStatisticsStore is always constructed / used / destroyed on the *main* thread.
WebResourceLoadStatisticsStore::m_statisticsStore however is always constructed / used / destroyed on the background queue.
Comment 13 Chris Dumez 2019-07-03 15:11:45 PDT
Comment on attachment 370256 [details]
Patch for landing

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

>> Source/WebKit/NetworkProcess/Classifier/WebResourceLoadStatisticsStore.cpp:628
>> +    ASSERT(!RunLoop::isMain());
> 
> This is not OK, the whole point of our abstraction is that WebResourceLoadStatisticsStore is always constructed / used / destroyed on the *main* thread.
> WebResourceLoadStatisticsStore::m_statisticsStore however is always constructed / used / destroyed on the background queue.

I will follow-up.
Comment 14 Ryosuke Niwa 2019-07-04 02:11:49 PDT
(In reply to Chris Dumez from comment #13)
> Comment on attachment 370256 [details]
> Patch for landing
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=370256&action=review
> 
> >> Source/WebKit/NetworkProcess/Classifier/WebResourceLoadStatisticsStore.cpp:628
> >> +    ASSERT(!RunLoop::isMain());
> > 
> > This is not OK, the whole point of our abstraction is that WebResourceLoadStatisticsStore is always constructed / used / destroyed on the *main* thread.
> > WebResourceLoadStatisticsStore::m_statisticsStore however is always constructed / used / destroyed on the background queue.
> 
> I will follow-up.

Where is the follow up happening?
Comment 15 Ryan Haddad 2019-07-04 13:59:57 PDT
(In reply to Ryosuke Niwa from comment #14)
> (In reply to Chris Dumez from comment #13)
> > I will follow-up.
> 
> Where is the follow up happening?
https://bugs.webkit.org/show_bug.cgi?id=199468
Comment 16 Ryosuke Niwa 2019-07-04 14:47:20 PDT
(In reply to Ryan Haddad from comment #15)
> (In reply to Ryosuke Niwa from comment #14)
> > (In reply to Chris Dumez from comment #13)
> > > I will follow-up.
> > 
> > Where is the follow up happening?
> https://bugs.webkit.org/show_bug.cgi?id=199468

Thanks!