Skip to content

Commit 0dd6d70

Browse files
committed
Core: save session as soon as a the sequence is incremented
Just be safe, let's not wait until other part of the code saves the session, and let's do it right here on the spot, where we know it changes. @Laituex was having a ErrCode=32 'msg_seqno too low' problem and this is the second thing we suspected to be the culprit, because if there's any issue (e.g. exception) that makes the session not be saved after the sequence got incremented, then an old sequence would be used the next time upon loading an old session file. (Backported from sochix@1b06473)
1 parent 79ad0fc commit 0dd6d70

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

src/TgSharp.Core/Network/MtProtoSender.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,11 @@ public MtProtoSender(TcpTransport transport, ISessionStore sessionStore, Session
3838
private int GenerateSequence(bool confirmed)
3939
{
4040
lock (session.Lock) {
41-
return confirmed ? session.Sequence++ * 2 + 1 : session.Sequence * 2;
41+
try {
42+
return confirmed ? session.Sequence++ * 2 + 1 : session.Sequence * 2;
43+
} finally {
44+
sessionStore.Save(session);
45+
}
4246
}
4347
}
4448

0 commit comments

Comments
 (0)