Telegram.Bot icon indicating copy to clipboard operation
Telegram.Bot copied to clipboard

TaskCanceledException

Open jcmag opened this issue 10 years ago • 12 comments

Hi,

I get sometimes this TaskCanceledException:

System.Threading.Tasks.TaskCanceledException: A task was canceled. at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.ConfiguredTaskAwaitable'1.ConfiguredTaskAwaiter.GetResult() at Telegram.Bot.Api.<SendWebRequest>d__89'1.MoveNext() in D:\Bitbucket\Bot\Telegram.Bot\Api.cs:line 1060 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter'1.GetResult() at Telegram.Bot.Service.Core.<SendMessageHtml>d__17.MoveNext() in D:\Bitbucket\Bot\Telegram.Bot.Service\Core.cs:line 291

It comes from this line, in Api.SendWebRequest: response = await client.PostAsync(uri, form).ConfigureAwait(false);

Do you know the reason?

jcmag avatar May 26 '16 22:05 jcmag

I have the same problem! It occurs when I'm sending video files with moderate size, event with 5MB in size. Maybe slow connection causes this exception!

Sedighzade avatar May 27 '16 21:05 Sedighzade

The default timeout is 1 min. Have you tried increasing it? It's TelegramBotClient.UploadTimeout in the current 10.x beta and Api.UploadTimeout before.

thoemmi avatar May 27 '16 22:05 thoemmi

I've increased the UploadTimeout, I'll see if the exception occurs again. But my bot is on a server with a gigabit connection... Is there anything else which can generate this exception?

jcmag avatar May 28 '16 12:05 jcmag

made this better to understand by warping the exception in an ApiRequestException

MrRoundRobin avatar May 29 '16 02:05 MrRoundRobin

Looks like this happens because httpClient.Timout is set to "timeout" parameter + 1 second. If request is not completed in timeout + 1 seconds, it will throw an error. And as I understand this can happen easily if there are some lags in connection.

bacr avatar Jun 07 '16 05:06 bacr

Have the same problem, when use subscribing on event Api.UpdateReceived. Sometimes this exception randomly throws from Api and crashs my app. Is there the way for me to handle this exception anyway becides the AppDomain.CurrentDomain.UnhandledException =)

KozhevnikovDmitry avatar Jun 16 '16 09:06 KozhevnikovDmitry

what version do you use?

MrRoundRobin avatar Jun 16 '16 09:06 MrRoundRobin

<package id="Telegram.Bot" version="9.0.0" targetFramework="net45" />

KozhevnikovDmitry avatar Jun 16 '16 10:06 KozhevnikovDmitry

@KozhevnikovDmitry I think you can handle these exceptions by putting a try catch around the StartReceiving

mhverbakel avatar Jul 06 '16 10:07 mhverbakel

StartReceiving isn't throwing exceptions. the exceptions which occur during Receiving will be emit the OnReceiveError event

MrRoundRobin avatar Jul 06 '16 16:07 MrRoundRobin

That's what I need.

KozhevnikovDmitry avatar Jul 07 '16 01:07 KozhevnikovDmitry

Seems to me that the issue can be closed if it is fixed now...?

mhverbakel avatar Jul 08 '16 02:07 mhverbakel