A fully open source & end-to-end encrypted note taking alternative to Evernote.
TypeScript asp-net-coredotnet-coreelectronfosshacktoberfestnote-managmentnote-takingnote-taking-appnotebooknotesnotes-appopen-sourceopensourceprivacyproductivityreactreact-nativereactjsself-hosted
fix: properly handle concurrent syncs
thecodrr27dade850a91
diff --git a/packages/core/api/sync/index.js b/packages/core/api/sync/index.jsindex 22e8ba764..e44c8bd91 100644--- a/packages/core/api/sync/index.js+++ b/packages/core/api/sync/index.js@@ -8,7 +8,6 @@ import Constants from "../../utils/constants";import TokenManager from "../token-manager";import Collector from "./collector";import { areAllEmpty } from "./utils";-import { Mutex } from "async-mutex";import * as signalr from "@microsoft/signalr";import Merger from "./merger";import Conflicts from "./conflicts";@@ -53,33 +52,40 @@ export default class SyncManager {*/constructor(db) {this.sync = new Sync(db);- this.syncMutex = new Mutex();+ this.isSyncing = false;}async start(full, force) {- if (this.syncMutex.isLocked()) {- throw new Error("A sync is already in progress.");- }+ if (this.isSyncing) return false;++ try {+ this.isSyncing = true;- return this.syncMutex.runExclusive(async () => {await this.sync.autoSync.start();- try {- await this.sync.start(full, force);- } catch (e) {- var isHubException = e.message.includes("HubException:");- if (isHubException) {- var actualError = /HubException: (.*)/gm.exec(e.message);- if (actualError.length > 1) throw new Error(actualError[1]);- }- throw e;+ await this.sync.start(full, force);+ return true;+ } catch (e) {+ var isHubException = e.message.includes("HubException:");+ if (isHubException) {+ var actualError = /HubException: (.*)/gm.exec(e.message);+ if (actualError.length > 1) throw new Error(actualError[1]);}- });+ throw e;+ } finally {+ this.isSyncing = false;+ }}async acquireLock(callback) {- this.sync.autoSync.stop();- await this.syncMutex.runExclusive(callback);- await this.sync.autoSync.start();+ try {+ this.isSyncing = true;++ this.sync.autoSync.stop();+ await callback();+ await this.sync.autoSync.start();+ } finally {+ this.isSyncing = false;+ }}async stop() {