diff --git a/packages/platform/src/resource.ts b/packages/platform/src/resource.ts index a6507aef51..cd903867a5 100644 --- a/packages/platform/src/resource.ts +++ b/packages/platform/src/resource.ts @@ -79,23 +79,42 @@ async function loadPlugin (id: Plugin): Promise { plugin: id }) pluginLoader = monitor(status, getLocation(id)()).then(async (plugin) => { - try { - // In case of ts-node, we have a bit different import structure, so let's check for it. - if (typeof plugin.default === 'object') { - // eslint-disable-next-line @typescript-eslint/return-await - return await (plugin as any).default.default() + return await retryLoading(async () => { + try { + // In case of ts-node, we have a bit different import structure, so let's check for it. + if (typeof plugin.default === 'object') { + // eslint-disable-next-line @typescript-eslint/return-await + return await (plugin as any).default.default() + } + return await plugin.default() + } catch (err: any) { + console.error(err) + throw err } - return await plugin.default() - } catch (err: any) { - console.error(err) - throw err - } + }) }) loading.set(id, pluginLoader) } return await pluginLoader } +async function retryLoading (op: () => Promise): Promise { + let lastErr: any + for (let i = 0; i < 3; i++) { + try { + return await op() + } catch (err: any) { + if (/Loading chunk [\d]+ failed/.test(err.message)) { + // Do not report on console and try to load again. + // After a short delay + await new Promise((resolve) => setTimeout(resolve, 50)) + } + lastErr = err + } + } + throw lastErr +} + const cachedResource = new Map() /** diff --git a/server/account/src/index.ts b/server/account/src/index.ts index c9774da4d8..26a8d7ca05 100644 --- a/server/account/src/index.ts +++ b/server/account/src/index.ts @@ -771,18 +771,17 @@ export async function upgradeWorkspace ( } const versionStr = versionToString(version) - const currentVersion = await db.collection(WORKSPACE_COLLECTION).findOne({ workspace: ws.workspace }) console.log( `${forceUpdate ? 'force-' : ''}upgrade from "${ - currentVersion?.version !== undefined ? versionToString(currentVersion.version) : '' + ws?.version !== undefined ? versionToString(ws.version) : '' }" to "${versionStr}"` ) - if (currentVersion?.version !== undefined && !forceUpdate && versionStr === versionToString(currentVersion.version)) { + if (ws?.version !== undefined && !forceUpdate && versionStr === versionToString(ws.version)) { return versionStr } await db.collection(WORKSPACE_COLLECTION).updateOne( - { workspace: ws.workspace }, + { _id: ws._id }, { $set: { version } }