From 4b67b7eedbe0dcbbba484c0361eb9f24b523e67d Mon Sep 17 00:00:00 2001 From: Abdullah Atta Date: Mon, 22 May 2023 18:22:32 +0500 Subject: [PATCH] sync: prevent multiple syncs from a single connection --- Notesnook.API/Hubs/SyncHub.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Notesnook.API/Hubs/SyncHub.cs b/Notesnook.API/Hubs/SyncHub.cs index 160eadb..be8b59c 100644 --- a/Notesnook.API/Hubs/SyncHub.cs +++ b/Notesnook.API/Hubs/SyncHub.cs @@ -111,7 +111,9 @@ namespace Notesnook.API.Hubs var userId = Context.User.FindFirstValue("sub"); if (string.IsNullOrEmpty(userId)) return 0; - var others = Clients.OthersInGroup(userId); + // Only allow a single sync to run per connection. This prevents a bunch of issues like sync loops + // and wasted bandwidth + if (GlobalSync.IsSyncRunning(userId, Context.ConnectionId)) return 0; if (!GlobalSync.RunningSyncs.ContainsKey(userId)) GlobalSync.RunningSyncs[userId] = new List();