sochix / TLSharp

Telegram client library implemented in C#
1.01k stars 380 forks source link

TelegramClient.IsConnected is not working as expected #936

Open solarin opened 4 years ago

solarin commented 4 years ago

we have discussed about this, and it seemed to be fixed with the new pr #931

But there are still some cases when it's not working as expected. Consider this real scenario:

ConnectAsync
            await sender.Send(invokewithLayer, token).ConfigureAwait(false);
            await sender.Receive(invokewithLayer, token).ConfigureAwait(false);

Send or Receive generate an exception, which is caught at the higher level which, in turn, checks whether Client.IsConnected to eventually reconnect.

At this point IsConnected = true, but the handhaking failed, hence it's not connected.

VictorShap commented 4 years ago

I have the same problem

solarin commented 4 years ago

I have the same problem

yes, this should be fixed and the solution might no be easy

VictorShap commented 4 years ago

Okay, could you tell me, when you find the solution

knocte commented 4 years ago

Does #937 fix this issue?

solarin commented 4 years ago

yes, if you push this fix, i'll push the other fix for the choice of the data center

knocte commented 4 years ago

Why is #937 connected to the MediaOnly issue?

solarin commented 4 years ago

written in the prose

yes, filtering the MediaOnly also fixes the problem, but ReconnectToDcAsync should also be fixed because it creates a TcpTransport, then it calls ConnectAsync which basically reloads the session with the old datacenter address and recreates a new TcpTransport. my proposed solution is that ReconnectToDcAsync does not recreate a TcpTransport, but saves the session after updating the new datacenter. then everything stays as it is.

solarin commented 4 years ago

Why is #937 connected to the MediaOnly issue?

long story short is that if i fix MediaOnly problem, it's still not working, because the new datacenter is ignored. #937 must be pushed in order for the data center selection to work properly, regardless of the MediaOnly thing

solarin commented 4 years ago

maybe my new pr will answer clearer the question