From f2e6696f21c4e641f5fb9e124478024c36c992c1 Mon Sep 17 00:00:00 2001 From: Isak Naslund Date: Thu, 3 Nov 2022 14:02:29 +0100 Subject: [PATCH] Adding lock around the upgrader loop in the ToNewVersion method. --- Versioning_Engine/Convert/ToNewVersion.cs | 54 ++++++++++++----------- 1 file changed, 29 insertions(+), 25 deletions(-) diff --git a/Versioning_Engine/Convert/ToNewVersion.cs b/Versioning_Engine/Convert/ToNewVersion.cs index cd6bafed7..16813722a 100644 --- a/Versioning_Engine/Convert/ToNewVersion.cs +++ b/Versioning_Engine/Convert/ToNewVersion.cs @@ -83,38 +83,40 @@ public static BsonDocument ToNewVersion(this BsonDocument document, string versi // Get the list of upgraders to call List versions = Query.UpgradersToCall(version); - // Call all the upgraders in sequence - for (int i = 0; i < versions.Count; i++) + lock (m_versioningLock) { - // Create a connection with the upgrader - NamedPipeServerStream pipe = GetPipe(versions[i]); - if (pipe == null) - return document; + // Call all the upgraders in sequence + for (int i = 0; i < versions.Count; i++) + { + // Create a connection with the upgrader + NamedPipeServerStream pipe = GetPipe(versions[i]); + if (pipe == null) + return document; - // Send the document - SendDocument(document, pipe); + // Send the document + SendDocument(document, pipe); - // Get the new version back - BsonDocument result = ReadDocument(pipe); - if (result != null) - { - if (result.Contains("_t") && result["_t"] == "NoUpdate") + // Get the new version back + BsonDocument result = ReadDocument(pipe); + if (result != null) { - if (result.Contains("Message")) + if (result.Contains("_t") && result["_t"] == "NoUpdate") { - noUpdateMessage = result["Message"].ToString(); - Engine.Base.Compute.RecordError(noUpdateMessage); - } - } - else if (document != result) - { - wasUpdated = true; - document = result; - } - } + if (result.Contains("Message")) + { + noUpdateMessage = result["Message"].ToString(); + Engine.Base.Compute.RecordError(noUpdateMessage); + } + } + else if (document != result) + { + wasUpdated = true; + document = result; + } + } + } } - // Record the fact that a document needed to be upgraded if (wasUpdated || noUpdateMessage != null) { @@ -234,6 +236,8 @@ private static BsonDocument ReadDocument(PipeStream pipe) private static Dictionary m_Pipes = new Dictionary(); + private static object m_versioningLock = new object(); + /***************************************************/ } }