Skip to content

Only retry DOMException/DOMError #2919

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

Merged
merged 7 commits into from
Apr 20, 2020
Merged

Conversation

schmidt-sebastian
Copy link
Contributor

@schmidt-sebastian schmidt-sebastian commented Apr 16, 2020

Limit the number of errors that can be retried on the AsyncQueue to those thrown by browsers.

Addresses #2755

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Apr 16, 2020

Binary Size Report

Affected SDKs

  • @firebase/firestore

    Type Base (7396d48) Head (5581429) Diff
    browser 253 kB 248 kB -5.40 kB (-2.1%)
    esm2017 200 kB 194 kB -5.47 kB (-2.7%)
    main 487 kB 488 kB +521 B (+0.1%)
    module 251 kB 246 kB -5.41 kB (-2.2%)
  • @firebase/firestore/memory

    Type Base (7396d48) Head (5581429) Diff
    browser 200 kB 195 kB -4.47 kB (-2.2%)
    esm2017 156 kB 152 kB -4.50 kB (-2.9%)
    main 377 kB 377 kB +128 B (+0.0%)
    module 198 kB 194 kB -4.47 kB (-2.3%)
  • firebase

    Type Base (7396d48) Head (5581429) Diff
    firebase-firestore.js 295 kB 289 kB -5.42 kB (-1.8%)
    firebase-firestore.memory.js 243 kB 238 kB -4.47 kB (-1.8%)
    firebase.js 828 kB 823 kB -5.42 kB (-0.7%)

Test Logs

@@ -20,8 +20,8 @@
"test:all": "run-p test:browser test:travis test:minified",
"test:browser": "karma start --single-run",
"test:browser:debug": "karma start --browsers=Chrome --auto-watch",
"test:node": "FIRESTORE_EMULATOR_PORT=8080 FIRESTORE_EMULATOR_PROJECT_ID=test-emulator TS_NODE_CACHE=NO TS_NODE_COMPILER_OPTIONS='{\"module\":\"commonjs\"}' nyc --reporter lcovonly -- mocha 'test/{,!(browser)/**/}*.test.ts' --file index.node.ts --opts ../../config/mocha.node.opts",
"test:node:prod": "TS_NODE_CACHE=NO TS_NODE_COMPILER_OPTIONS='{\"module\":\"commonjs\"}' nyc --reporter lcovonly -- mocha 'test/{,!(browser)/**/}*.test.ts' --file index.node.ts --opts ../../config/mocha.node.opts",
"test:node": "FIRESTORE_EMULATOR_PORT=8080 FIRESTORE_EMULATOR_PROJECT_ID=test-emulator TS_NODE_CACHE=NO TS_NODE_COMPILER_OPTIONS='{\"module\":\"commonjs\"}' nyc --reporter lcovonly -- mocha 'test/{,!(browser)/**/}*.test.ts' --file index.node.ts --file test/util/node_persistence.ts --opts ../../config/mocha.node.opts",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

While this seems wrong, this is needed to pull in DOMException. Since USE_MOCK_PERSISTENCE is not set, there are no other side effects. I chose not to rename this file since it is used in our test launchers.

// We only retry errors that match the ones thrown by IndexedDB (see
// https://developer.mozilla.org/en-US/docs/Web/API/IDBTransaction/error)
if (
(typeof DOMException !== 'undefined' &&
Copy link
Contributor

Choose a reason for hiding this comment

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

DOMException can mean just about any failure in the browser. A better way to handle this would be to take the transaction.error property and wrap it in our own PersistenceError error type (or similar). That way it's unambiguous that it's an error that came from IndexedDB. This also sidesteps the issue of the availability of the DOMException type.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. I am now wrapping exceptions thrown by abort and error in their own types.

Copy link
Contributor

@wilhuff wilhuff left a comment

Choose a reason for hiding this comment

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

LGTM with some final nits

constructor(cause: Error) {
super(
Code.UNKNOWN,
'IndexedDB transaction failed with environment error: ' + cause
Copy link
Contributor

Choose a reason for hiding this comment

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

Drop "with environment error". "IndexedDB transaction failed" is enough to indicate what's failing and the cause will carry the details.


constructor(cause: Error) {
super(
Code.UNKNOWN,
Copy link
Contributor

Choose a reason for hiding this comment

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

UNAVAILABLE could be a better code for this given what we know about when this happens.

* exception. All retryable operations are executed in order and only run
* if all prior operations were retried successfully.
* A retryable operation is rescheduled with backoff if it fails with a
* SimpleDbTransactionError (the error type used by SimpleDb). All
Copy link
Contributor

Choose a reason for hiding this comment

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

The error is actually IndexedDbTransactionError.

@wilhuff wilhuff removed their assignment Apr 20, 2020
@schmidt-sebastian schmidt-sebastian merged commit d7c9ed4 into master Apr 20, 2020
@firebase firebase locked and limited conversation to collaborators May 21, 2020
@schmidt-sebastian schmidt-sebastian deleted the mrschmidt/limitretries branch July 9, 2020 17:45
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants