RESOLVED FIXED 212608
Any active sqlite transactions for the ITP database should be aborted when the network process suspends.
https://bugs.webkit.org/show_bug.cgi?id=212608
Summary Any active sqlite transactions for the ITP database should be aborted when th...
Kate Cheney
Reported 2020-06-01 13:26:01 PDT
We should abort ITP database transactions that are not finished when the network process suspends, otherwise the unfinished transaction will hold the lock of the database file.
Attachments
Patch (7.78 KB, patch)
2020-06-01 13:47 PDT, Kate Cheney
no flags
Patch (6.55 KB, patch)
2020-06-02 18:13 PDT, Kate Cheney
no flags
Patch (7.05 KB, patch)
2020-06-03 11:09 PDT, Kate Cheney
no flags
Kate Cheney
Comment 1 2020-06-01 13:27:13 PDT
Kate Cheney
Comment 2 2020-06-01 13:47:32 PDT
Kate Cheney
Comment 3 2020-06-02 14:49:48 PDT
I talked with Sihui offline and we are not convinced aborting transactions will solve the issue, mainly because there is time between when NetworkProcess::prepareToSuspend() is called and when the process actually suspends. So it is unlikely that a previous transaction in the ITP database is still occurring after the process has suspended. This indicates the problem could be that the thread is not being stopped properly in the call to WebResourceLoadStatistics::suspend(). I posted a patch adding debug asserts to this area of code in: https://bugs.webkit.org/show_bug.cgi?id=212663 to get more information.
Chris Dumez
Comment 4 2020-06-02 16:03:20 PDT
(In reply to katherine_cheney from comment #3) > I talked with Sihui offline and we are not convinced aborting transactions > will solve the issue, mainly because there is time between when > NetworkProcess::prepareToSuspend() is called and when the process actually > suspends. So it is unlikely that a previous transaction in the ITP database > is still occurring after the process has suspended. This indicates the > problem could be that the thread is not being stopped properly in the call > to WebResourceLoadStatistics::suspend(). > > I posted a patch adding debug asserts to this area of code in: > https://bugs.webkit.org/show_bug.cgi?id=212663 to get more information. If aborting transactions is what IDB does, I think ITP should do the same. A transaction can take a large amount of time when when you get a PrepareToSuspend, you may get suspended fairly quick after, especially in the case of imminent suspension.
Chris Dumez
Comment 5 2020-06-02 16:20:31 PDT
Comment on attachment 400755 [details] Patch I am 90% sure this is wrong and re-introducing a bug that we fixed recently. I am a bit sad that the API tests are not failing since I think we added a test to cover that. The reason WebResourceLoadStatisticsStore was static was that there is only one shared queue nowadays. You don't want to go through every store and hang each queue separately because they all share the same queue..
Chris Dumez
Comment 6 2020-06-02 16:21:43 PDT
(In reply to Chris Dumez from comment #5) > Comment on attachment 400755 [details] > Patch > > I am 90% sure this is wrong and re-introducing a bug that we fixed recently. > I am a bit sad that the API tests are not failing since I think we added a > test to cover that. The reason WebResourceLoadStatisticsStore was static was > that there is only one shared queue nowadays. You don't want to go through > every store and hang each queue separately because they all share the same > queue.. See Bug 211207.
Kate Cheney
Comment 7 2020-06-02 16:23:43 PDT
(In reply to Chris Dumez from comment #5) > Comment on attachment 400755 [details] > Patch > > I am 90% sure this is wrong and re-introducing a bug that we fixed recently. > I am a bit sad that the API tests are not failing since I think we added a > test to cover that. The reason WebResourceLoadStatisticsStore was static was > that there is only one shared queue nowadays. You don't want to go through > every store and hang each queue separately because they all share the same > queue.. Hmm I see. I am not sure how to access the database object from a static function, then, am I missing something obvious?
Chris Dumez
Comment 8 2020-06-02 16:28:36 PDT
(In reply to katherine_cheney from comment #7) > (In reply to Chris Dumez from comment #5) > > Comment on attachment 400755 [details] > > Patch > > > > I am 90% sure this is wrong and re-introducing a bug that we fixed recently. > > I am a bit sad that the API tests are not failing since I think we added a > > test to cover that. The reason WebResourceLoadStatisticsStore was static was > > that there is only one shared queue nowadays. You don't want to go through > > every store and hang each queue separately because they all share the same > > queue.. > > Hmm I see. I am not sure how to access the database object from a static > function, then, am I missing something obvious? Maybe you can keep a static HashMap of all ResourceLoadStatisticsDatabaseStore objects which you only modify / query from the background ITP queue. Then in the static suspend, you dispatch to the background queue, iterate through each ResourceLoadStatisticsDatabaseStore object in the map to interrupt their transactions and only then suspend the thread.
Kate Cheney
Comment 9 2020-06-02 18:13:42 PDT
Chris Dumez
Comment 10 2020-06-03 10:39:57 PDT
Comment on attachment 400873 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=400873&action=review Please add a static allStores() function to ResourceLoadStatisticsDatabaseStore and move the logic there. Then you add to the HashSet in the ResourceLoadStatisticsDatabaseStore constructor and remove in the ResourceLoadStatisticsDatabaseStore destructor. > Source/WebKit/NetworkProcess/Classifier/WebResourceLoadStatisticsStore.cpp:178 > + static NeverDestroyed<HashMap<WebResourceLoadStatisticsStore*, ResourceLoadStatisticsDatabaseStore*>> map; Why isn't this a HashSet<ResourceLoadStatisticsDatabaseStore*> ? > Source/WebKit/NetworkProcess/Classifier/WebResourceLoadStatisticsStore.cpp:179 > + return map; I would ASSERT(!RunLoop::isMain()); in here. > Source/WebKit/NetworkProcess/Classifier/WebResourceLoadStatisticsStore.cpp:199 > + statisticsDatabaseStoreMap().add(this, downcast<ResourceLoadStatisticsDatabaseStore>(m_statisticsStore.get())); You add but never remove.
Chris Dumez
Comment 11 2020-06-03 10:42:08 PDT
Comment on attachment 400873 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=400873&action=review > Source/WebKit/NetworkProcess/Classifier/WebResourceLoadStatisticsStore.cpp:1436 > + for (auto& databaseStore : statisticsDatabaseStoreMap().values()) Your code is not thread-safe either since you iterate over the map in the background thread but populate the map in the main thread. When I suggested this, I said the HashMap should only be modified / queried on the background queue.
Chris Dumez
Comment 12 2020-06-03 10:44:42 PDT
Comment on attachment 400873 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=400873&action=review >> Source/WebKit/NetworkProcess/Classifier/WebResourceLoadStatisticsStore.cpp:1436 >> + for (auto& databaseStore : statisticsDatabaseStoreMap().values()) > > Your code is not thread-safe either since you iterate over the map in the background thread but populate the map in the main thread. When I suggested this, I said the HashMap should only be modified / queried on the background queue. Never mind this comment, from the diff output, I missed that you were populating in the background queue.
Kate Cheney
Comment 13 2020-06-03 11:09:53 PDT
Chris Dumez
Comment 14 2020-06-03 11:11:21 PDT
Comment on attachment 400946 [details] Patch r=me
EWS
Comment 15 2020-06-03 12:13:30 PDT
Committed r262505: <https://trac.webkit.org/changeset/262505> All reviewed patches have been landed. Closing bug and clearing flags on attachment 400946 [details].
Note You need to log in before you can comment on or make changes to this bug.