TgSharp icon indicating copy to clipboard operation
TgSharp copied to clipboard

`System.InvalidOperationException: Couldn't read the packet length` when trying to run AuthUser test in macOS

Open knocte opened this issue 5 years ago • 11 comments

System.InvalidOperationException : Couldn't read the packet length
Stack trace:
  at TgSharp.Core.Network.TcpTransport.Receive (System.Threading.CancellationToken token) [0x000d5] in /Users/knocte/Documents/Code/TgSharpLAITEUX/src/TgSharp.Core/Network/TcpTransport.cs:59 
  at TgSharp.Core.Network.MtProtoSender.Receive (TgSharp.TL.TLMethod request, System.Threading.CancellationToken token) [0x0003a] in /Users/knocte/Documents/Code/TgSharpLAITEUX/src/TgSharp.Core/Network/MtProtoSender.cs:144 
  at TgSharp.Core.TelegramClient.RequestWithDcMigration (TgSharp.TL.TLMethod request, System.Threading.CancellationToken token) [0x0010d] in /Users/knocte/Documents/Code/TgSharpLAITEUX/src/TgSharp.Core/TelegramClient.cs:178 
  at TgSharp.Core.TelegramClient.SendCodeRequestAsync (System.String phoneNumber, System.Threading.CancellationToken token) [0x0009b] in /Users/knocte/Documents/Code/TgSharpLAITEUX/src/TgSharp.Core/TelegramClient.cs:208 
  at TgSharp.Tests.TgSharpTests.AuthUser () [0x000cd] in /Users/knocte/Documents/Code/TgSharpLAITEUX/src/TgSharp.Tests/TgSharpTests.cs:129 
  at TgSharp.Tests.TgSharpTestsNUnit.AuthUser () [0x00020] in /Users/knocte/Documents/Code/TgSharpLAITEUX/src/TgSharp.Tests.NUnit/Test.cs:21 
  at TgSharp.Core.Network.TcpTransport.Receive (System.Threading.CancellationToken token) [0x000d5] in /Users/knocte/Documents/Code/TgSharpLAITEUX/src/TgSharp.Core/Network/TcpTransport.cs:59 
  at TgSharp.Core.Network.MtProtoSender.Receive (TgSharp.TL.TLMethod request, System.Threading.CancellationToken token) [0x0003a] in /Users/knocte/Documents/Code/TgSharpLAITEUX/src/TgSharp.Core/Network/MtProtoSender.cs:144 
  at TgSharp.Core.TelegramClient.RequestWithDcMigration (TgSharp.TL.TLMethod request, System.Threading.CancellationToken token) [0x0010d] in /Users/knocte/Documents/Code/TgSharpLAITEUX/src/TgSharp.Core/TelegramClient.cs:178 
  at TgSharp.Core.TelegramClient.SendCodeRequestAsync (System.String phoneNumber, System.Threading.CancellationToken token) [0x0009b] in /Users/knocte/Documents/Code/TgSharpLAITEUX/src/TgSharp.Core/TelegramClient.cs:208 
  at TgSharp.Tests.TgSharpTests.AuthUser () [0x000cd] in /Users/knocte/Documents/Code/TgSharpLAITEUX/src/TgSharp.Tests/TgSharpTests.cs:129 
  at NUnit.Framework.AsyncInvocationRegion+AsyncTaskInvocationRegion.WaitForPendingOperationsToComplete (System.Object invocationResult) [0x0003c] in <65d21fba48bf4534bebbb82a4e22f339>:0 
  at NUnit.Core.NUnitAsyncTestMethod.RunTestMethod () [0x00013] in <65d21fba48bf4534bebbb82a4e22f339>:0 

knocte avatar Sep 15 '20 08:09 knocte

Try removing Session.dat inside TgSharp.Tests.NUnit\bin\Debug

aarani avatar Sep 15 '20 09:09 aarani

@aarani why would a session.dat file cause this? can you explain?

knocte avatar Sep 15 '20 09:09 knocte

because TgSharp doesn't handle 404 error (auth_key not found caused by auth_key being wrong/corrupted) and 404 error causes TgSharp to throw this exception. for debugging it more, set a breakpoint on "throw" line, run binaryreader(whatever it's name is).ReadInt32() It should give you the error code .

aarani avatar Sep 15 '20 09:09 aarani

The fact that why that auth_key gets corrupted needs more debugging I saw @Laiteux comment in #18 which stated that our current FileSessionStore is corrupting AuthKey sometimes which is worrisome if true and can be the culprit here.

aarani avatar Sep 15 '20 09:09 aarani

Check if it happens with JsonFileSessionStore

Laiteux avatar Sep 15 '20 09:09 Laiteux

because TgSharp doesn't handle 404 error (auth_key not found caused by auth_key) and 404 error causes TgSharp to throw this exception.

that doesn't explain anything related to a .dat file?

Check if it happens with JsonFileSessionStore

well, in fact I was testing this on a branch with JSON files, but I still don't understand how the session store could be related to this?

knocte avatar Sep 15 '20 15:09 knocte

which stated that our current FileSessionStore is corrupting AuthKey

I don't find that comment; can you repeat it @Laiteux ?

knocte avatar Sep 15 '20 15:09 knocte

that doesn't explain anything related to a .dat file?

I don't understand what you're asking, can you rephrase that?

I don't find that comment; can you repeat it @Laiteux ?

https://github.com/nblockchain/TgSharp/pull/18#issuecomment-691866813

aarani avatar Sep 15 '20 17:09 aarani

I don't understand what you're asking, can you rephrase that?

To your sentence "Try removing Session.dat", I asked "why would a session.dat file cause this? can you explain?", and you said some things which are completely unrelated to the session.dat file. How can that be related?

#18 (comment)

Matt is talking about the .dat file getting corrupted. That file happens to have an auth_key but I don't think he's saying anything related to authentication or networking (which is what this github issue is about).

knocte avatar Sep 15 '20 17:09 knocte

why would a session.dat file cause this? can you explain?

because that's the place we store the authorization key and if you have broken session.dat It causes that error.

aarani avatar Sep 15 '20 18:09 aarani

Ok as I said in Telegram to the author I mistaken "Couldn't read the packet length" with "Can't decode packet" (LOL). So all I said isn't really related to this error. It's probably some compatibility issue with Mono in mac and TgSharp since then the author is going to try using our new .NET Standard version and see if it fixes anything

aarani avatar Sep 15 '20 18:09 aarani