Prevent recursive issue when client is disposed in OnOther

This commit is contained in:
Wizou 2024-06-15 02:35:38 +02:00
parent 865c841bd6
commit 85cc404213
3 changed files with 11 additions and 7 deletions

2
FAQ.md
View file

@ -59,7 +59,7 @@ You also need to obtain their `access_hash` which is specific to the resource yo
This serves as a proof that the logged-in user is entitled to access that channel/user/photo/document/... This serves as a proof that the logged-in user is entitled to access that channel/user/photo/document/...
(otherwise, anybody with the ID could access it) (otherwise, anybody with the ID could access it)
> A small private `Chat` don't need an access_hash and can be queried using their `chat_id` only. > A small private group `Chat` don't need an access_hash and can be queried using their `chat_id` only.
However most common chat groups are not `Chat` but a `Channel` supergroup (without the `broadcast` flag). See [Terminology in ReadMe](README.md#terminology). However most common chat groups are not `Chat` but a `Channel` supergroup (without the `broadcast` flag). See [Terminology in ReadMe](README.md#terminology).
Some TL methods only applies to private `Chat`, some only applies to `Channel` and some to both. Some TL methods only applies to private `Chat`, some only applies to `Channel` and some to both.

View file

@ -181,7 +181,7 @@ namespace WTelegram
{ {
Helpers.Log(2, $"{_dcSession.DcID}>Disposing the client"); Helpers.Log(2, $"{_dcSession.DcID}>Disposing the client");
Reset(false, IsMainDC); Reset(false, IsMainDC);
var ex = new TaskCanceledException("WTelegram.Client was disposed"); var ex = new ObjectDisposedException("WTelegram.Client was disposed");
lock (_pendingRpcs) // abort all pending requests lock (_pendingRpcs) // abort all pending requests
foreach (var rpc in _pendingRpcs.Values) foreach (var rpc in _pendingRpcs.Values)
rpc.tcs.TrySetException(ex); rpc.tcs.TrySetException(ex);
@ -349,7 +349,7 @@ namespace WTelegram
lock (_pendingRpcs) // retry all pending requests lock (_pendingRpcs) // retry all pending requests
{ {
foreach (var rpc in _pendingRpcs.Values) foreach (var rpc in _pendingRpcs.Values)
rpc.tcs.SetResult(reactorError); // this leads to a retry (see Invoke<T> method) rpc.tcs.TrySetResult(reactorError); // this leads to a retry (see Invoke<T> method)
_pendingRpcs.Clear(); _pendingRpcs.Clear();
_bareRpc = null; _bareRpc = null;
} }
@ -359,7 +359,7 @@ namespace WTelegram
RaiseUpdates(updatesState); RaiseUpdates(updatesState);
} }
} }
catch catch (Exception e) when (e is not ObjectDisposedException)
{ {
if (IsMainDC) if (IsMainDC)
RaiseUpdates(reactorError); RaiseUpdates(reactorError);
@ -947,7 +947,8 @@ namespace WTelegram
} }
finally finally
{ {
lock (_session) _session.Save(); if (_reactorTask != null) // client not disposed
lock (_session) _session.Save();
} }
Helpers.Log(2, $"Connected to {(TLConfig.test_mode ? "Test DC" : "DC")} {TLConfig.this_dc}... {TLConfig.flags & (Config.Flags)~0x18E00U}"); Helpers.Log(2, $"Connected to {(TLConfig.test_mode ? "Test DC" : "DC")} {TLConfig.this_dc}... {TLConfig.flags & (Config.Flags)~0x18E00U}");
} }

View file

@ -13,7 +13,10 @@
<PackageId>WTelegramClient</PackageId> <PackageId>WTelegramClient</PackageId>
<Version>0.0.0</Version> <Version>0.0.0</Version>
<Authors>Wizou</Authors> <Authors>Wizou</Authors>
<Description>Telegram Client API (MTProto) library written 100% in C# and .NET Standard | Latest API layer: 181&#10;&#10;Release Notes:&#10;$(ReleaseNotes.Replace("|", "%0D%0A").Replace(" - ","%0D%0A- ").Replace(" ", "%0D%0A%0D%0A"))</Description> <Description>Telegram Client API (MTProto) library written 100% in C# and .NET Standard | Latest API layer: 181
Release Notes:
$(ReleaseNotes.Replace("|", "%0D%0A").Replace(" - ","%0D%0A- ").Replace(" ", "%0D%0A%0D%0A"))</Description>
<Copyright>Copyright © Olivier Marcoux 2021-2024</Copyright> <Copyright>Copyright © Olivier Marcoux 2021-2024</Copyright>
<PackageLicenseExpression>MIT</PackageLicenseExpression> <PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageProjectUrl>https://wiz0u.github.io/WTelegramClient</PackageProjectUrl> <PackageProjectUrl>https://wiz0u.github.io/WTelegramClient</PackageProjectUrl>
@ -48,7 +51,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'"> <ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
<PackageReference Include="IndexRange" Version="1.0.2" /> <PackageReference Include="IndexRange" Version="1.0.3" />
<PackageReference Include="System.Memory" Version="4.5.5" /> <PackageReference Include="System.Memory" Version="4.5.5" />
<PackageReference Include="System.Text.Json" Version="6.0.5" /> <PackageReference Include="System.Text.Json" Version="6.0.5" />
<PackageReference Include="System.Collections.Immutable" Version="6.0.0" /> <PackageReference Include="System.Collections.Immutable" Version="6.0.0" />