Skip to content

Commit 9b01100

Browse files
committed
fix(Account#sync): Do not re-init account if failsafe triggers
Signed-off-by: Marcel Klehr <[email protected]>
1 parent 3fcfcfd commit 9b01100

File tree

1 file changed

+26
-16
lines changed

1 file changed

+26
-16
lines changed

src/lib/Account.ts

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,13 @@ import { isTest } from './isTest'
1313
import { setUser, setContext, withScope, captureException } from '@sentry/browser'
1414
import AsyncLock from 'async-lock'
1515
import CachingTreeWrapper from './CachingTreeWrapper'
16-
import { UnexpectedFolderPathError } from '../errors/Error'
16+
import {
17+
ClientsideAdditionFailsafeError, ClientsideDeletionFailsafeError,
18+
InterruptedSyncError,
19+
NetworkError,
20+
ServersideAdditionFailsafeError, ServersideDeletionFailsafeError,
21+
UnexpectedFolderPathError
22+
} from '../errors/Error'
1723

1824
declare const IS_BROWSER: boolean
1925

@@ -382,6 +388,16 @@ export default class Account {
382388
await this.server.onSyncFail()
383389
}
384390

391+
if (IS_BROWSER) {
392+
// eslint-disable-next-line no-undef
393+
if (self.constructor.name === 'ServiceWorkerGlobalScope' || (typeof chrome !== 'undefined' && 'offscreen' in chrome)) {
394+
const {destroyOffscreen} = await import('./offscreen')
395+
// We destroy the offscreen page when the sync is done to allow the worker to be killed
396+
await destroyOffscreen()
397+
clearInterval(this.offscreenPingInterval)
398+
}
399+
}
400+
385401
this.syncing = false
386402

387403
await this.setData({
@@ -390,25 +406,19 @@ export default class Account {
390406
syncing: false,
391407
scheduled: false,
392408
})
393-
if (matchAllErrors(e, e => e.code !== 27 && (!isTest || e.code !== 26))) {
409+
if (matchAllErrors(e, e => ![
410+
new InterruptedSyncError().code,
411+
new NetworkError().code,
412+
new ServersideAdditionFailsafeError(0).code,
413+
new ServersideDeletionFailsafeError(0).code,
414+
new ClientsideAdditionFailsafeError(0).code,
415+
new ClientsideDeletionFailsafeError(0).code,
416+
].includes(e.code) && (!isTest || e.code !== 26))) {
394417
await this.storage.setCurrentContinuation(null)
395-
}
396-
397-
// reset cache and mappings after error
398-
// (but not after interruption or NetworkError)
399-
if (matchAllErrors(e, e => e.code !== 27 && e.code !== 17 && (!isTest || e.code !== 26))) {
400418
await this.init()
401419
}
402420
}
403-
if (IS_BROWSER) {
404-
// eslint-disable-next-line no-undef
405-
if (self.constructor.name === 'ServiceWorkerGlobalScope' || (typeof chrome !== 'undefined' && 'offscreen' in chrome)) {
406-
const {destroyOffscreen} = await import('./offscreen')
407-
// We destroy the offscreen page when the sync is done to allow the worker to be killed
408-
await destroyOffscreen()
409-
}
410-
}
411-
clearInterval(this.offscreenPingInterval)
421+
412422
this.syncProcess = null
413423
this.localCachingResource = null
414424
await Logger.persist()

0 commit comments

Comments
 (0)