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

Handle async index db initialization errors, fixes tutadb 1805 #7068

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/api/worker/EventBusClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import { SleepDetector } from "./utils/SleepDetector.js"
import sysModelInfo from "../entities/sys/ModelInfo.js"
import tutanotaModelInfo from "../entities/tutanota/ModelInfo.js"
import { resolveTypeReference } from "../common/EntityFunctions.js"
import { ReportedMailFieldMarker, PhishingMarkerWebsocketData, PhishingMarkerWebsocketDataTypeRef } from "../entities/tutanota/TypeRefs"
import { PhishingMarkerWebsocketData, PhishingMarkerWebsocketDataTypeRef, ReportedMailFieldMarker } from "../entities/tutanota/TypeRefs"
import { UserFacade } from "./facades/UserFacade"
import { ExposedProgressTracker } from "../main/ProgressTracker.js"

Expand Down Expand Up @@ -558,7 +558,6 @@ export class EventBusClient {
await this.processEventBatch(modification)
} catch (e) {
console.log("ws error while processing event batches", e)
this.listener.onError(e)
throw e
}

Expand Down
1 change: 1 addition & 0 deletions src/api/worker/WorkerImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ export class WorkerImpl implements NativeInterface {
// Otherwise uncaught error handler might end up in an infinite loop for test cases.
if (workerScope && !isMainOrNode()) {
workerScope.addEventListener("unhandledrejection", (event: PromiseRejectionEvent) => {
console.error("workerImpl.unhandledrejection", event, event.reason)
this.sendError(event.reason)
})

Expand Down
6 changes: 3 additions & 3 deletions src/api/worker/search/DbFacade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export class DbFacade {
private _activeTransactions: number
indexingSupported: boolean = true

constructor(version: number, onupgrade: (event: any, db: IDBDatabase, dbFacade: DbFacade) => void) {
constructor(version: number, onupgrade: (event: any, db: IDBDatabase, dbFacade: DbFacade) => Promise<void> | void) {
this._activeTransactions = 0
this._db = new LazyLoaded(() => {
if (!this.indexingSupported) {
Expand Down Expand Up @@ -86,11 +86,11 @@ export class DbFacade {
}
}

DBOpenRequest.onupgradeneeded = (event: IDBVersionChangeEvent) => {
DBOpenRequest.onupgradeneeded = async (event: IDBVersionChangeEvent) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

This callback is not async and I think we'll have problems if we try to assume it's async.

I wonder if we can block it here Atomics.wait() somehow, probably not without another worker?

//console.log("upgrade db", event)
try {
// @ts-ignore
onupgrade(event, event.target.result, this)
await onupgrade(event, event.target.result, this)
} catch (e) {
reject(new DbError("could not create object store for DB " + this._id, e))
}
Expand Down