mirror of
https://github.com/wiz0u/WTelegramClient.git
synced 2025-12-06 06:52:01 +01:00
Retry API call once on error -503 Timeout
This commit is contained in:
parent
722a8313b0
commit
f282d270ae
|
|
@ -371,10 +371,7 @@ If you are not in a Console app or don't want the logs on screen, you can redire
|
|||
// • Log to VS Output debugging pane in addition to default Console screen logging:
|
||||
WTelegram.Helpers.Log += (lvl, str) => System.Diagnostics.Debug.WriteLine(str);
|
||||
|
||||
// • Log to file in replacement of default Console screen logging:
|
||||
WTelegram.Helpers.Log = (lvl, str) => File.AppendAllText("WTelegram.log", str + Environment.NewLine);
|
||||
|
||||
// • More efficient example with a static variable and detailed logging to file:
|
||||
// • Log to file in replacement of default Console screen logging, using this static variable:
|
||||
static StreamWriter WTelegramLogs = new StreamWriter("WTelegram.log", true, Encoding.UTF8) { AutoFlush = true };
|
||||
...
|
||||
WTelegram.Helpers.Log = (lvl, str) => WTelegramLogs.WriteLine($"{DateTime.Now:yyyy-MM-dd HH:mm:ss} [{"TDIWE!"[lvl]}] {str}");
|
||||
|
|
|
|||
|
|
@ -40,6 +40,8 @@ namespace WTelegram
|
|||
public int FloodRetryThreshold { get; set; } = 60;
|
||||
/// <summary>Number of seconds between each keep-alive ping. Increase this if you have a slow connection or you're debugging your code</summary>
|
||||
public int PingInterval { get; set; } = 60;
|
||||
/// <summary>Size of chunks when uploading/downloading files. Reduce this if you don't have much memory</summary>
|
||||
public int FilePartSize { get; set; } = 512 * 1024;
|
||||
/// <summary>Is this Client instance the main or a secondary DC session</summary>
|
||||
public bool IsMainDC => (_dcSession?.DataCenter?.id ?? 0) == _session.MainDC;
|
||||
/// <summary>Has this Client established connection been disconnected?</summary>
|
||||
|
|
@ -68,7 +70,6 @@ namespace WTelegram
|
|||
private Task _connecting;
|
||||
private CancellationTokenSource _cts;
|
||||
private int _reactorReconnects = 0;
|
||||
private const int FilePartSize = 512 * 1024;
|
||||
private const string ConnectionShutDown = "Could not read payload length : Connection shut down";
|
||||
private readonly SemaphoreSlim _parallelTransfers = new(10); // max parallel part uploads/downloads
|
||||
private readonly SHA256 _sha256 = SHA256.Create();
|
||||
|
|
@ -840,6 +841,7 @@ namespace WTelegram
|
|||
var tcs = new TaskCompletionSource<object>(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
lock (_pendingRequests)
|
||||
_pendingRequests[msgId] = (typeof(X), tcs);
|
||||
bool got503 = false;
|
||||
var result = await tcs.Task;
|
||||
switch (result)
|
||||
{
|
||||
|
|
@ -873,6 +875,11 @@ namespace WTelegram
|
|||
goto retry;
|
||||
}
|
||||
}
|
||||
else if (rpcError.error_code == -503 && !got503)
|
||||
{
|
||||
got503 = true;
|
||||
goto retry;
|
||||
}
|
||||
else if (rpcError.error_code == 500 && rpcError.error_message == "AUTH_RESTART")
|
||||
{
|
||||
_session.UserId = 0; // force a full login authorization flow, next time
|
||||
|
|
|
|||
|
|
@ -120,7 +120,7 @@ namespace WTelegram
|
|||
private int _nextPosition = 8;
|
||||
|
||||
public SessionStore(string pathname)
|
||||
: base(pathname, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None, 1) // no buffering
|
||||
: base(pathname, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None, 1) // no in-app buffering
|
||||
{
|
||||
if (base.Read(_header, 0, 8) == 8)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -15527,7 +15527,7 @@ namespace TL
|
|||
/// <param name="peer">Peer</param>
|
||||
/// <param name="id">Message ID</param>
|
||||
/// <param name="reaction">Get only reactions of this type (UTF8 emoji)</param>
|
||||
/// <param name="offset">Offset (typically taken from the <c>next_offset</c> field of the returned <see cref="MessageReactionsList"/>)</param>
|
||||
/// <param name="offset">Offset (typically taken from the <c>next_offset</c> field of the returned <see cref="Messages_MessageReactionsList"/>)</param>
|
||||
/// <param name="limit">Maximum number of results to return, <a href="https://corefork.telegram.org/api/offsets">see pagination</a></param>
|
||||
public static Task<Messages_MessageReactionsList> Messages_GetMessageReactionsList(this Client client, InputPeer peer, int id, int limit = int.MaxValue, string reaction = null, string offset = null)
|
||||
=> client.Invoke(new Messages_GetMessageReactionsList
|
||||
|
|
|
|||
Loading…
Reference in a new issue