Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

REGRESSION (iOS 16): LocalStorage writes fail after ~2.5MB #4758

Conversation

szewai
Copy link
Contributor

@szewai szewai commented Sep 27, 2022

0297f12

REGRESSION (iOS 16): LocalStorage writes fail after ~2.5MB
https://bugs.webkit.org/show_bug.cgi?id=245479
<rdar://100252023>

Reviewed by Chris Dumez.

We set the maximum size of LocalStorage database to be 5MB, because quota is 5MB. But SQLite has overhead, which means
the file size can reach 5MB when the stored content is much smaller than that. To avoid this issue, now we let
SQLiteStorageArea keep track of the actual content size and use that size to do quota computation, instead of setting
hard limit on database file.

* Source/WebKit/NetworkProcess/storage/SQLiteStorageArea.cpp:
(WebKit::SQLiteStorageArea::isEmpty):
(WebKit::SQLiteStorageArea::prepareDatabase):
(WebKit::SQLiteStorageArea::startTransactionIfNecessary):
(WebKit::SQLiteStorageArea::getItem):
(WebKit::SQLiteStorageArea::getAllItemsFromDatabase):
(WebKit::SQLiteStorageArea::initializeCache):
(WebKit::SQLiteStorageArea::allItems):
(WebKit::SQLiteStorageArea::setItem):
(WebKit::SQLiteStorageArea::removeItem):
(WebKit::SQLiteStorageArea::clear):
* Source/WebKit/NetworkProcess/storage/SQLiteStorageArea.h:

Canonical link: https://commits.webkit.org/255044@main

b7e1da2

Misc iOS, tvOS & watchOS macOS Linux Windows
βœ… πŸ§ͺ style βœ… πŸ›  ios βœ… πŸ›  mac   πŸ›  wpe
βœ… πŸ›  ios-sim   πŸ›  mac-debug βœ… πŸ›  gtk βœ… πŸ›  wincairo
βœ… πŸ§ͺ webkitperl   πŸ§ͺ ios-wk2   πŸ›  mac-AS-debug   πŸ§ͺ gtk-wk2
  πŸ§ͺ api-ios   πŸ§ͺ api-mac   πŸ§ͺ api-gtk
βœ… πŸ›  tv   πŸ§ͺ mac-wk1
βœ… πŸ›  tv-sim βœ… πŸ§ͺ mac-wk2
βœ… πŸ›  πŸ§ͺ merge βœ… πŸ›  watch   πŸ§ͺ mac-AS-debug-wk2
βœ… πŸ›  watch-sim βœ… πŸ§ͺ mac-wk2-stress

@szewai szewai requested a review from cdumez as a code owner September 27, 2022 17:43
@szewai szewai self-assigned this Sep 27, 2022
@szewai szewai added WebKit Nightly Build Website Storage Bugs related to storage APIs, including IndexedDB and localStorage labels Sep 27, 2022
@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label Sep 27, 2022
@szewai szewai removed the merging-blocked Applied to prevent a change from being merged label Sep 29, 2022
@szewai szewai force-pushed the eng/REGRESSION-iOS-16-LocalStorage-is-cleared-after-writing-data-of-more-than-2-5MB branch from d95d64c to 98a2302 Compare September 29, 2022 16:52
@szewai szewai force-pushed the eng/REGRESSION-iOS-16-LocalStorage-is-cleared-after-writing-data-of-more-than-2-5MB branch from 98a2302 to 636c90b Compare September 29, 2022 20:08
@geoffreygaren
Copy link
Contributor

Is it really true that exceeding quota currently erases all your (under-quota) LocalStorage? If so, does this patch address that symptom?

@szewai
Copy link
Contributor Author

szewai commented Sep 29, 2022

Is it really true that exceeding quota currently erases all your (under-quota) LocalStorage? If so, does this patch address that symptom?

In network process, all updates in the same transaction will be lost because transaction is aborted. Normally we commit 500ms after transaction starts (e3fff83).
For web process, it currently clears cached items in memory on quota error.

@geoffreygaren
Copy link
Contributor

For web process, it currently clears all items in memory on quota error.

I see: Not all items are lost, just all items in the current 500ms batch.

@geoffreygaren geoffreygaren changed the title REGRESSION (iOS 16): LocalStorage is cleared after writing data of more than ~2.5MB REGRESSION (iOS 16): LocalStorage writes fail after ~2.5MB Sep 29, 2022
@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label Sep 29, 2022
@szewai szewai removed the merging-blocked Applied to prevent a change from being merged label Sep 30, 2022
@szewai szewai force-pushed the eng/REGRESSION-iOS-16-LocalStorage-is-cleared-after-writing-data-of-more-than-2-5MB branch from 636c90b to 52bbe8f Compare September 30, 2022 00:11
@szewai szewai changed the title REGRESSION (iOS 16): LocalStorage writes fail after ~2.5MB REGRESSION (iOS 16): LocalStorage is cleared after writing data of more than ~2.5MB Sep 30, 2022
@szewai szewai force-pushed the eng/REGRESSION-iOS-16-LocalStorage-is-cleared-after-writing-data-of-more-than-2-5MB branch from 52bbe8f to 7fe083a Compare September 30, 2022 00:20
@szewai szewai changed the title REGRESSION (iOS 16): LocalStorage is cleared after writing data of more than ~2.5MB REGRESSION (iOS 16): LocalStorage writes fail after ~2.5MB Sep 30, 2022
@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label Sep 30, 2022
Copy link
Contributor

@cdumez cdumez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@szewai szewai removed the merging-blocked Applied to prevent a change from being merged label Sep 30, 2022
@szewai szewai force-pushed the eng/REGRESSION-iOS-16-LocalStorage-is-cleared-after-writing-data-of-more-than-2-5MB branch from 7fe083a to b7e1da2 Compare September 30, 2022 19:00
@szewai szewai added the merge-queue Applied to send a pull request to merge-queue label Sep 30, 2022
https://bugs.webkit.org/show_bug.cgi?id=245479
<rdar://100252023>

Reviewed by Chris Dumez.

We set the maximum size of LocalStorage database to be 5MB, because quota is 5MB. But SQLite has overhead, which means
the file size can reach 5MB when the stored content is much smaller than that. To avoid this issue, now we let
SQLiteStorageArea keep track of the actual content size and use that size to do quota computation, instead of setting
hard limit on database file.

* Source/WebKit/NetworkProcess/storage/SQLiteStorageArea.cpp:
(WebKit::SQLiteStorageArea::isEmpty):
(WebKit::SQLiteStorageArea::prepareDatabase):
(WebKit::SQLiteStorageArea::startTransactionIfNecessary):
(WebKit::SQLiteStorageArea::getItem):
(WebKit::SQLiteStorageArea::getAllItemsFromDatabase):
(WebKit::SQLiteStorageArea::initializeCache):
(WebKit::SQLiteStorageArea::allItems):
(WebKit::SQLiteStorageArea::setItem):
(WebKit::SQLiteStorageArea::removeItem):
(WebKit::SQLiteStorageArea::clear):
* Source/WebKit/NetworkProcess/storage/SQLiteStorageArea.h:

Canonical link: https://commits.webkit.org/255044@main
@webkit-early-warning-system webkit-early-warning-system force-pushed the eng/REGRESSION-iOS-16-LocalStorage-is-cleared-after-writing-data-of-more-than-2-5MB branch from b7e1da2 to 0297f12 Compare September 30, 2022 20:37
@webkit-commit-queue
Copy link
Collaborator

Committed 255044@main (0297f12): https://commits.webkit.org/255044@main

Reviewed commits have been landed. Closing PR #4758 and removing active labels.

@webkit-early-warning-system webkit-early-warning-system merged commit 0297f12 into WebKit:main Sep 30, 2022
@webkit-commit-queue webkit-commit-queue removed the merge-queue Applied to send a pull request to merge-queue label Sep 30, 2022
@szewai szewai deleted the eng/REGRESSION-iOS-16-LocalStorage-is-cleared-after-writing-data-of-more-than-2-5MB branch November 14, 2022 20:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Website Storage Bugs related to storage APIs, including IndexedDB and localStorage
Projects
None yet
6 participants