Discord.Net
Discord.Net copied to clipboard
[Bug]: HTTPS connection issues after bot has been idle for more than a few minutes.
Check The Docs
- [X] I double checked the docs and couldn't find any useful information.
Verify Issue Source
- [X] I verified the issue was caused by Discord.Net.
Check your intents
- [X] I double checked that I have the required intents.
Description
Hey there, developers!
I'm making this issue to - well - report an issue with Discord.NET, specifically when a bot command is run after the bot has been idle for a little while. To give some context:
- A user runs a command at let's say 10:30am
- The bot is left idle after that command has finished executing
- Another command is run at let's say, between 10:45am and 11:00am on the same day.
- The below exception is thrown.
I would like to point out that once a command has thrown this error, any commands run in the 10 minute period after this command is run will run successfully. As such, I've asked users to start using the /ping command to let it crash before executing what command they actually need to run. This however isn't an optimal solution as it's rather inconvenient and ideally I'd like for the bot not to crash when commands are run whatsoever.
This error always comes from calling the InteractionService#ExecuteCommandAsync task. I think I've exhausted all of my own debugging efforts now, as I've been trying to fix this for a while to the point where I do not believe it is my own code causing this.
For some additional information, the method that calls the function that causes this error is below:
I really hope somebody could be of assistance towards my issue here, as I am yet to find any solution and/or pointers via online research - the D.NET/Discord Bots discord servers have also not been any help.
Version
3.7.2
Working Version
N/A
Logs
[03:08:07] [ERROR]: [InteractionCreated] threw an exception.
Error: System.Net.Http.HttpRequestException: The SSL connection could not be established, see inner exception.
---> System.Security.Authentication.AuthenticationException: Authentication failed, see inner exception.
---> System.ComponentModel.Win32Exception (0x80090326): The message received was unexpected or badly formatted.
--- End of inner exception stack trace ---
at System.Net.Security.SslStream.ForceAuthenticationAsync[TIOAdapter](TIOAdapter adapter, Boolean receiveFirst, Byte[] reAuthenticationData, Boolean isApm)
at System.Net.Http.ConnectHelper.EstablishSslConnectionAsync(SslClientAuthenticationOptions sslOptions, HttpRequestMessage request, Boolean async, Stream stream, CancellationToken cancellationToken)
--- End of inner exception stack trace ---
at System.Net.Http.ConnectHelper.EstablishSslConnectionAsync(SslClientAuthenticationOptions sslOptions, HttpRequestMessage request, Boolean async, Stream stream, CancellationToken cancellationToken)
at System.Net.Http.HttpConnectionPool.ConnectAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
at System.Net.Http.HttpConnectionPool.CreateHttp11ConnectionAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
at System.Net.Http.HttpConnectionPool.AddHttp11ConnectionAsync(HttpRequestMessage request)
at System.Threading.Tasks.TaskCompletionSourceWithCancellation`1.WaitWithCancellationAsync(CancellationToken cancellationToken)
at System.Net.Http.HttpConnectionPool.GetHttp11ConnectionAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
at System.Net.Http.HttpConnectionPool.SendWithVersionDetectionAndRetryAsync(HttpRequestMessage request, Boolean async, Boolean doRequestAuth, CancellationToken cancellationToken)
at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
at System.Net.Http.DecompressionHandler.SendAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
at System.Net.Http.HttpClient.<SendAsync>g__Core|83_0(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationTokenSource cts, Boolean disposeCts, CancellationTokenSource pendingRequestsCts, CancellationToken originalCancellationToken)
at Discord.Net.Rest.DefaultRestClient.SendInternalAsync(HttpRequestMessage request, CancellationToken cancelToken, Boolean headerOnly)
at Discord.Net.Rest.DefaultRestClient.SendAsync(String method, String endpoint, String json, CancellationToken cancelToken, Boolean headerOnly, String reason)
at Discord.Net.Queue.JsonRestRequest.SendAsync()
at Discord.Net.Queue.RequestBucket.SendAsync(RestRequest request)
at Discord.Net.Queue.RequestQueue.SendAsync(RestRequest request)
at Discord.API.DiscordRestApiClient.SendInternalAsync(String method, String endpoint, RestRequest request)
at Discord.API.DiscordRestApiClient.SendJsonAsync(String method, String endpoint, Object payload, BucketId bucketId, ClientBucketType clientBucket, RequestOptions options)
at Discord.API.DiscordRestApiClient.CreateInteractionResponseAsync(InteractionResponse response, UInt64 interactionId, String interactionToken, RequestOptions options)
at Discord.WebSocket.SocketCommandBase.DeferAsync(Boolean ephemeral, RequestOptions options)
at HangoutBot2.Engine.Handlers.Interactions.InteractionHandler.OnInteractionCreated(SocketInteraction interaction) in D:\SourceCode\HangoutBot2\HangoutBot2\HangoutBot2\Engine\Handlers\Interactions\InteractionHandler.cs:line 1369
Sample
internal async Task OnInteractionCreated(SocketInteraction interaction)
{
try
{
Log.Info("New interaction of type {0} created.", interaction.Type.ToString());
switch (interaction.Type)
{
// When slash commands are executed:
case InteractionType.ApplicationCommand:
// Ensure a Configuration File has been created in the DB
if (interaction.Channel is SocketGuildChannel guildChannel)
{
EnsureBotConfigurationCreated(guildChannel.Guild.Id);
}
Log.Info("(/) Slash Command executed by {0}", interaction.User.Username);
var context = new InteractionContext(Bot.Instance.Client, interaction, interaction.Channel);
if (!interaction.HasResponded)
{
await interaction.DeferAsync();
}
var result = await Service.ExecuteCommandAsync(context, Bot.Instance.ServiceProvider);
Log.Info("Slash command result: {0}", result.ToString());
break;
}
}
catch (Exception e)
{
Log.Error("[InteractionCreated] threw an exception. {0}", e.ToString());
if (interaction.HasResponded)
{
await interaction.ModifyOriginalResponseAsync(x =>
{
x.Content = $"{Emojis.Error} An error has occured whilst attempting to execute this interaction. The developers will have been notified, if it's important.";
});
}
else
{
await interaction.RespondAsync($"{Emojis.Error} An error has occured whilst attempting to execute this interaction. The developers will have been notified, if it's important.");
}
}
Packages
Discord.Net: ---
Discord.Net.Commands v3.7.2 Discord.Net.Core v3.7.2 Discord.Net.Interactions v3.7.2 Discord.Net.Rest v3.7.2 Discord.Net.Webhook v3.7.2 Discord.Net.WebSocket v3.7.2
HtmlAgilityPack (writing HTML files) v1.11.43 Microsoft.Extensions.DependencyInjection.Abstractions v6.0.21.52210 Microsoft.Extension.DependencyInjection v6.0.21.55210 Microsoft.Win32.SystemEvents v4.700.19.56404 (no idea why this is here to be honest) Newtonsoft.Json v13.0.1.25517 System.Data.SqlClient v4.700.20.6702 System.Data.SQLite v1.0.115.5 System.Data.SQLite.EF6 v1.0.115.5 Dapper v2.0.123.33578