From c6aa4c208ec5851db60431b36cbe0e2450bfd9e5 Mon Sep 17 00:00:00 2001 From: Eduardo Date: Thu, 19 Sep 2024 12:54:06 -0400 Subject: [PATCH 1/2] adding timeout to sweep and blocked handling --- src/telemetry/logging.ts | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/src/telemetry/logging.ts b/src/telemetry/logging.ts index 1bf20cf30..6063aa58d 100644 --- a/src/telemetry/logging.ts +++ b/src/telemetry/logging.ts @@ -154,6 +154,10 @@ async function openLoggingDB() { }, blocked(currentVersion: number, blockedVersion: number) { console.debug("Database blocked.", { currentVersion, blockedVersion }); + // This should never happen, since we immediately close connections if blocking below, + // but just in case, close the connection here so it doesn't block openLoggingDB from + // resolving + database?.close(); }, blocking(currentVersion: number, blockedVersion: number) { // Don't block closing/upgrading the database @@ -249,7 +253,9 @@ export async function clearLog(context: MessageContext = {}): Promise { const db = await openLoggingDB(); try { - const tx = db.transaction(ENTRY_OBJECT_STORE, "readwrite"); + const tx = db.transaction(ENTRY_OBJECT_STORE, "readwrite", { + durability: "relaxed", + }); if (isEmpty(context)) { await tx.store.clear(); @@ -278,7 +284,9 @@ export async function getLogEntries( try { const objectStore = db - .transaction(ENTRY_OBJECT_STORE, "readonly") + .transaction(ENTRY_OBJECT_STORE, "readonly", { + durability: "relaxed", + }) .objectStore(ENTRY_OBJECT_STORE); let indexKey: IndexKey | undefined; @@ -515,7 +523,9 @@ export async function clearModComponentDebugLogs( const db = await openLoggingDB(); try { - const tx = db.transaction(ENTRY_OBJECT_STORE, "readwrite"); + const tx = db.transaction(ENTRY_OBJECT_STORE, "readwrite", { + durability: "relaxed", + }); const index = tx.store.index("modComponentId"); for await (const cursor of index.iterate(modComponentId)) { if (cursor.value.level === "debug" || cursor.value.level === "trace") { @@ -546,15 +556,26 @@ async function _sweepLogs(): Promise { }); const db = await openLoggingDB(); + const abortController = new AbortController(); + // Ensure in cases where the sweep is taking too long, we abort the operation to reduce the likelihood + // of blocking other db transactions. + const timeoutId = setTimeout(abortController.abort, 30_000); try { - const tx = db.transaction(ENTRY_OBJECT_STORE, "readwrite"); + const tx = db.transaction(ENTRY_OBJECT_STORE, "readwrite", { + durability: "relaxed", + }); let deletedCount = 0; // Ideally this would be ordered by timestamp to delete the oldest records, but timestamp is not an index. // This might mostly "just work" if the cursor happens to iterate in insertion order for await (const cursor of tx.store) { + if (abortController.signal.aborted) { + console.warn("Log sweep aborted due to timeout"); + break; + } + await cursor.delete(); deletedCount++; @@ -563,6 +584,7 @@ async function _sweepLogs(): Promise { } } } finally { + clearTimeout(timeoutId); db.close(); } } From cc518ff49df26a63af9d8f07430ff87cb0fc6336 Mon Sep 17 00:00:00 2001 From: Eduardo Date: Thu, 19 Sep 2024 14:20:30 -0400 Subject: [PATCH 2/2] improve inclusivity --- src/auth/featureFlags.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/auth/featureFlags.ts b/src/auth/featureFlags.ts index d6d4275d2..f8b0efadc 100644 --- a/src/auth/featureFlags.ts +++ b/src/auth/featureFlags.ts @@ -101,12 +101,12 @@ export const FeatureFlags = { SETTINGS_EXPERIMENTAL: "settings-experimental", /** - * PixieBrix error service kill switch/ + * PixieBrix error service off switch/ */ ERROR_SERVICE_DISABLE_REPORT: "error-service-disable-report", /** - * Datadog error telemetry kill switch. + * Datadog error telemetry off switch. * * Originally introduced when moving Datadog to the offscreen document in order to turn off error telemetry if * the offscreen document implementation was buggy. @@ -115,7 +115,7 @@ export const FeatureFlags = { "application-error-telemetry-disable-report", /** - * IndexDB logging kill switch. This disables writing to the LOG database, along with + * IndexDB logging off switch. This disables writing to the LOG database, along with * the clear debug logging and sweep logs functionality. * * Introduced to mitigate issues around idb logging causing runtime performance issues. See: