From 66757ccd0b33428274fd3835e9f586971a16d931 Mon Sep 17 00:00:00 2001 From: Wizou Date: Mon, 27 Sep 2021 17:08:22 +0200 Subject: [PATCH] fix MT issue in session.Save --- src/Session.cs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/Session.cs b/src/Session.cs index 79243aa..2165835 100644 --- a/src/Session.cs +++ b/src/Session.cs @@ -88,12 +88,12 @@ namespace WTelegram encryptor.TransformFinalBlock(finalBlock, 0, utf8Json.Length & 15).CopyTo(output.AsMemory(48 + utf8Json.Length & ~15)); if (!File.Exists(_pathname)) File.WriteAllBytes(_pathname, output); - else - { - string tempPathname = _pathname + ".tmp"; - File.WriteAllBytes(tempPathname, output); - File.Replace(tempPathname, _pathname, null); - } + else lock (this) + { + string tempPathname = _pathname + ".tmp"; + File.WriteAllBytes(tempPathname, output); + File.Replace(tempPathname, _pathname, null); + } } internal (long msgId, int seqno) NewMsg(bool isContent) @@ -104,7 +104,6 @@ namespace WTelegram lock (this) { if (msgId <= CurrentDCSession.LastSentMsgId) msgId = CurrentDCSession.LastSentMsgId += 4; else CurrentDCSession.LastSentMsgId = msgId; - seqno = isContent ? CurrentDCSession.Seqno++ * 2 + 1 : CurrentDCSession.Seqno * 2; Save(); }