discord-net / Discord.Net

An unofficial .Net wrapper for the Discord API (https://discord.com/)
https://discordnet.dev
MIT License
3.33k stars 736 forks source link

TaskCanceledException with SendMessageAsync #613

Closed SubZero0 closed 7 years ago

SubZero0 commented 7 years ago

This is an intermittent problem that I'm having when trying to send a message.

Stacktrace 1: https://hastebin.com/vigocomafa.pas Line: https://github.com/SubZero0/DiscordNet-Docs/blob/master/src/DiscordNet/Handlers/CommandHandler.cs#L68

Stacktrace 2: https://hastebin.com/noyozisenu.cs Line: https://github.com/SubZero0/DiscordNet-Docs/blob/master/src/DiscordNet/Modules/Commands.cs#L173

In the first stacktrace I'm just sending one message, there's no reason to trigger the ratelimit, so I guess Discord.Net is trying to send it (and failing) a lot of times and triggering it itself (?).

Additional infomation: The bot is hosted on a Ubuntu 14.04 server with .NET Core 1.1. I couldnt reproduce on Windows 10.

I will probably try running the bot on another OS, like Ubuntu 16.04/CentOS/Debian, with a fresh install. I accept suggestions as well for what should be causing it or which OS should I try. =p

Auralytical commented 7 years ago

I suggest turning on debug logging which will show all outgoing requests and if there are any clustered together before the ratelimit is triggered.

SubZero0 commented 7 years ago

Couldnt get the ratelimit again. But the error is still there. Log with debug (the log starts when I sent the message):

Not awaiting the command handler: 1- https://hastebin.com/akexewinag.cs 2- https://hastebin.com/dirovuxide.cs

Awaiting the command handler: 1- https://hastebin.com/afeyasodab.sql

As it's possible to see, it receives the message but freezes the handler since the POST log only appears shortly before the exception. The Sync approach makes the bot lose connection since it freezes the heartbeat. It's possible to see there's no long running method inside the "info" command (https://github.com/SubZero0/DiscordNet-Docs/blob/master/src/DiscordNet/Modules/Commands.cs#L173).

SubZero0 commented 7 years ago

Tried changing the OS to CentOS 7.1 and Ubuntu 16.04 but the error still persists. No idea what could be causing it :S

Auralytical commented 7 years ago

There's only two things that should be able to cause a TaskCanceledException: logging out of the client (or disposing of it, or logging in again), or canceling the CancellationToken passed via RequestOptions, if any.

SubZero0 commented 7 years ago

I think it was related to where it was hosted. I don't know what was causing it but I changed my host and it looks like it's working fine. I'll close this since it doens't look like a lib-related issue.

Thanks Voltana.