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

fix: prevent silent failure when DOM storage quota exceeded #20899

Merged
merged 2 commits into from Nov 22, 2019

Conversation

jacobq
Copy link
Contributor

@jacobq jacobq commented Oct 31, 2019

Description of Change

This PR modifies dom_storage_limits.patch so that instead of (incompletely / incorrectly) circumventing the enforcement of the DOM storage quota, it is simply increased (from 10MiB to 100MiB). The primary motivation for this change is that the previous patch (see PR #15596) does not actually work properly (example).

As described in the updated patch notes, bypassing the maximum size enforcement in
StorageAreaImpl::Put
partially resolves the problem but can lead to undesirable side-effects (e.g. instability / poor performance).

Cc:
@deepak1556
@alexeykuzmin
@nornagon

Checklist

Release Notes

Notes: DOM storage quota enforcement re-enabled, but limit changed from 10MiB to 100MiB

@jacobq jacobq requested a review from a team as a code owner October 31, 2019 22:59
@electron-cation electron-cation bot added the new-pr 🌱 PR opened in the last 24 hours label Oct 31, 2019
@jacobq jacobq changed the title fix: prevent silent failure of DOM storage fix: prevent silent failure when DOM storage quota exceeded Oct 31, 2019
@jacobq jacobq changed the title fix: prevent silent failure when DOM storage quota exceeded WIP: fix: prevent silent failure when DOM storage quota exceeded Nov 1, 2019
@jacobq jacobq force-pushed the jrq/dom_storage_limit branch 2 times, most recently from af4c5dc to 6f008e2 Compare November 1, 2019 15:09
@jacobq
Copy link
Contributor Author

jacobq commented Nov 1, 2019

It seems that the patch is not being applied at the right time or something because I can see the following in src/out/Debug/gen/third_party/blink/public/mojom/dom_storage/storage_area.mojom.h:

  static constexpr uint32_t kPerStorageAreaQuota = 10485760U;
  
  static constexpr uint32_t kPerStorageAreaOverQuotaAllowance = 102400U;

which I suspect is derived from the unpatched src/content/browser/dom_storage/dom_storage_types.h

Update: I modified the patch so that it also updates this file now (not sure if there is a better way), and that seems to have done the trick.

@jacobq jacobq force-pushed the jrq/dom_storage_limit branch 2 times, most recently from 64b7fec to 5883a33 Compare November 1, 2019 17:53
@jacobq jacobq changed the title WIP: fix: prevent silent failure when DOM storage quota exceeded fix: prevent silent failure when DOM storage quota exceeded Nov 1, 2019
@jacobq
Copy link
Contributor Author

jacobq commented Nov 1, 2019

FYI The failing mac test appears to be a fluke (failure was caused by time out and the corresponding code should be completely unrelated to this PR).

@electron-cation electron-cation bot removed the new-pr 🌱 PR opened in the last 24 hours label Nov 1, 2019
@jacobq
Copy link
Contributor Author

jacobq commented Nov 10, 2019

Please let me know if there's anything that I can do to help land this fix.

@zcbenz
Copy link
Member

zcbenz commented Nov 13, 2019

This PR requires approval from @electron/wg-upgrades.

spec/chromium-spec.js Outdated Show resolved Hide resolved
Copy link
Member

@nornagon nornagon left a comment

Choose a reason for hiding this comment

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

This change seems good to me, just a couple of nitpicks! Thanks for your contribution :)

patches/chromium/dom_storage_limits.patch Outdated Show resolved Hide resolved
The previous version of this patch did not include
changes required to circumvent the quota enforcement
performed by StorageAreaImpl. Consequently when
the quota was exceeded, things still "appeared to
work" at first but then would later fail silently.
That is, the cache would be updated but the backing
store would not.

This could be fixed by disabling the code below
(from `content/browser/dom_storage/storage_area_impl.cc`)
```
  // Only check quota if the size is increasing, this allows
  // shrinking changes to pre-existing maps that are over budget.
  if (new_item_size > old_item_size && new_storage_used > max_size_) {
    if (map_state_ == MapState::LOADED_KEYS_ONLY) {
      receivers_.ReportBadMessage(
          "The quota in browser cannot exceed when there is only one "
          "renderer.");
    } else {
      std::move(callback).Run(false);
    }
    return;
  }
```

However, since this seems to have some unintended side-effects
(see updated notes in dom_storage_limits.patch) it seems
more prudent to simply increase the quota to a larger
yet still reasonable size rather than attempt to circumvent
the storage quota altogether.
@jacobq
Copy link
Contributor Author

jacobq commented Nov 14, 2019

Could you give the CI a kick? (lint failed due to "Error: socket hang up")

@jacobq
Copy link
Contributor Author

jacobq commented Nov 14, 2019

Looks like win-x64 could use a restart as well... the error looks unrelated:

not ok 443 <webview> tag <webview>.capturePage() returns a Promise with a NativeImage
  AssertionError: expected undefined to equal 6
      at Context.<anonymous> (C:\projects\src\electron\spec\webview-spec.js:1035:32)
[4576:1113/203523.801:WARNING:ipc_message_attachment_set.cc(49)] MessageAttachmentSet destroyed with unconsumed attachments: 0/1

@jacobq
Copy link
Contributor Author

jacobq commented Nov 22, 2019

@deepak1556 I'm sure you're busy, but would you mind taking a quick peek at this and letting me know if you notice anything major that needs to be addressed?

@jacobq
Copy link
Contributor Author

jacobq commented Nov 22, 2019

🙏 Thanks, Robo.

@deepak1556 deepak1556 merged commit a7c2f79 into electron:master Nov 22, 2019
@release-clerk
Copy link

release-clerk bot commented Nov 22, 2019

Release Notes Persisted

DOM storage quota enforcement re-enabled, but limit changed from 10MiB to 100MiB

jacobq added a commit to jacobq/electron that referenced this pull request Dec 4, 2019
…#20899)

* test: update DOM storage quota limits test

* fix: update dom_storage_limits.patch (fixes electron#13465)

The previous version of this patch did not include
changes required to circumvent the quota enforcement
performed by StorageAreaImpl. Consequently when
the quota was exceeded, things still "appeared to
work" at first but then would later fail silently.
That is, the cache would be updated but the backing
store would not.

This could be fixed by disabling the code below
(from `content/browser/dom_storage/storage_area_impl.cc`)
```
  // Only check quota if the size is increasing, this allows
  // shrinking changes to pre-existing maps that are over budget.
  if (new_item_size > old_item_size && new_storage_used > max_size_) {
    if (map_state_ == MapState::LOADED_KEYS_ONLY) {
      receivers_.ReportBadMessage(
          "The quota in browser cannot exceed when there is only one "
          "renderer.");
    } else {
      std::move(callback).Run(false);
    }
    return;
  }
```

However, since this seems to have some unintended side-effects
(see updated notes in dom_storage_limits.patch) it seems
more prudent to simply increase the quota to a larger
yet still reasonable size rather than attempt to circumvent
the storage quota altogether.
@trop
Copy link
Contributor

trop bot commented Dec 4, 2019

@jacobq has manually backported this PR to "8-x-y", please check out #21380

@trop trop bot added the in-flight/8-x-y label Dec 4, 2019
@jacobq
Copy link
Contributor Author

jacobq commented Dec 4, 2019

@jacobq has manually backported this PR to "8-x-y", please check out #21380

Hopefully this is the right process.... I just cherry-picked the squashed commit from this onto 8-x-y since I noticed that this didn't land in the latest beta (v8.0.0-beta.4).

jkleinsc pushed a commit that referenced this pull request Dec 4, 2019
…21380)

* test: update DOM storage quota limits test

* fix: update dom_storage_limits.patch (fixes #13465)

The previous version of this patch did not include
changes required to circumvent the quota enforcement
performed by StorageAreaImpl. Consequently when
the quota was exceeded, things still "appeared to
work" at first but then would later fail silently.
That is, the cache would be updated but the backing
store would not.

This could be fixed by disabling the code below
(from `content/browser/dom_storage/storage_area_impl.cc`)
```
  // Only check quota if the size is increasing, this allows
  // shrinking changes to pre-existing maps that are over budget.
  if (new_item_size > old_item_size && new_storage_used > max_size_) {
    if (map_state_ == MapState::LOADED_KEYS_ONLY) {
      receivers_.ReportBadMessage(
          "The quota in browser cannot exceed when there is only one "
          "renderer.");
    } else {
      std::move(callback).Run(false);
    }
    return;
  }
```

However, since this seems to have some unintended side-effects
(see updated notes in dom_storage_limits.patch) it seems
more prudent to simply increase the quota to a larger
yet still reasonable size rather than attempt to circumvent
the storage quota altogether.
@sofianguy sofianguy added this to Fixed in 8.0.0-beta.5 in 8.2.x Jan 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
8.2.x
Fixed in 8.0.0-beta.5
Development

Successfully merging this pull request may close these issues.

None yet

4 participants