Skip to content

Commit

Permalink
TL deserialization errors no longer cause a ReactorError. Renewing se…
Browse files Browse the repository at this point in the history
…ssion on layer change to prevent old layer messages
  • Loading branch information
wiz0u committed Jun 15, 2024
1 parent 85cc404 commit 1a00ae5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Examples/Program_ReactorError.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ private static async Task Client_OnOther(IObject arg)
await CreateAndConnect();
break;
}
catch (Exception ex)
catch (Exception ex) when (ex is not ObjectDisposedException)
{
Console.WriteLine("Connection still failing: " + ex.Message);
}
Expand Down
33 changes: 21 additions & 12 deletions src/Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -465,21 +465,29 @@ internal IObject ReadFrame(byte[] data, int dataLen)
Helpers.Log(1, $"{_dcSession.DcID}>Ignoring 0x{ctorNb:X8} because of wrong timestamp {msgStamp:u} - {utcNow:u} Δ={new TimeSpan(_dcSession.ServerTicksOffset):c}");
return null;
}
if (ctorNb == Layer.MsgContainerCtor)
{
Helpers.Log(1, $"{_dcSession.DcID}>Receiving {"MsgContainer",-40} {msgStamp:u} (svc)");
return ReadMsgContainer(reader);
}
else if (ctorNb == Layer.RpcResultCtor)
try
{
Helpers.Log(1, $"{_dcSession.DcID}>Receiving {"RpcResult",-40} {msgStamp:u}");
return ReadRpcResult(reader);
if (ctorNb == Layer.MsgContainerCtor)
{
Helpers.Log(1, $"{_dcSession.DcID}>Receiving {"MsgContainer",-40} {msgStamp:u} (svc)");
return ReadMsgContainer(reader);
}
else if (ctorNb == Layer.RpcResultCtor)
{
Helpers.Log(1, $"{_dcSession.DcID}>Receiving {"RpcResult",-40} {msgStamp:u}");
return ReadRpcResult(reader);
}
else
{
var obj = reader.ReadTLObject(ctorNb);
Helpers.Log(1, $"{_dcSession.DcID}>Receiving {obj.GetType().Name,-40} {msgStamp:u} {((seqno & 1) != 0 ? "" : "(svc)")} {((msgId & 2) == 0 ? "" : "NAR")}");
return obj;
}
}
else
catch (Exception ex)
{
var obj = reader.ReadTLObject(ctorNb);
Helpers.Log(1, $"{_dcSession.DcID}>Receiving {obj.GetType().Name,-40} {msgStamp:u} {((seqno & 1) != 0 ? "" : "(svc)")} {((msgId & 2) == 0 ? "" : "NAR")}");
return obj;
Helpers.Log(4, $"While deserializing frame #{ctorNb:x}: " + ex.ToString());
return null;
}
}

Expand Down Expand Up @@ -916,6 +924,7 @@ private async Task DoConnectAsync(bool quickResume)
TLConfig = new Config { this_dc = _session.MainDC, dc_options = _session.DcOptions };
else
{
if (_dcSession.Layer != 0 && _dcSession.Layer != Layer.Version) _dcSession.Renew();
var initParams = JSONValue.FromJsonElement(System.Text.Json.JsonDocument.Parse(Config("init_params")).RootElement);
TLConfig = await this.InvokeWithLayer(Layer.Version,
new TL.Methods.InitConnection<Config>
Expand Down

0 comments on commit 1a00ae5

Please sign in to comment.