WebSocketClient's KeepAliveInterval can't be disabled.
See original GitHub issueIn console window (OnLogMessage from DiscordBot):
[Gateway] Disconnected: Received close code 4002: Error while decoding payload.
In Visual Studio output window:
Exception thrown: 'Discord.Net.WebSocketException' in Discord.Net.dll
Exception thrown: 'System.Threading.Tasks.TaskCanceledException' in mscorlib.ni.dll
Exception thrown: 'System.Threading.Tasks.TaskCanceledException' in mscorlib.ni.dll
Exception thrown: 'Discord.Net.WebSocketException' in mscorlib.ni.dll
This occurs every 32.5 seconds when there is absolutely no activity in connected channels. With activity, this does not occur.
After disconnecting, Discord.Net reconnects and, if there is still no activity, it disconnects again after 32.5 seconds.
Guessing it has something to do with the heartbeat.
Using .Net Core RC2. Latest master branch from GitHub.
project.json:
{
"version": "1.0.0-*",
"buildOptions": {
"emitEntryPoint": true
},
"dependencies": {
"Newtonsoft.Json": "8.0.4-beta1",
"Discord.Net": "0.9.2"
},
"frameworks": {
"netstandard1.5": {
"imports": [
"portable-net451+win81"
]
}
},
"runtimes": {
"win81-x64": { }
}
}
Program.cs:
using System;
using System.Text;
using Discord;
namespace InactivityIssue
{
public class Program
{
public static void Main(string[] args) => new Program().Start();
private DiscordClient _client;
public void Start()
{
_client = new DiscordClient(x =>
{
x.LogLevel = LogSeverity.Debug;
x.LogHandler = OnLogMessage;
});
_client.ExecuteAndWait(async () =>
{
await _client.Connect("BOTTOKEN");
});
}
private void OnLogMessage(object sender, LogMessageEventArgs e)
{
//Color
ConsoleColor color;
switch (e.Severity)
{
case LogSeverity.Error: color = ConsoleColor.Red; break;
case LogSeverity.Warning: color = ConsoleColor.Yellow; break;
case LogSeverity.Info: color = ConsoleColor.White; break;
case LogSeverity.Verbose: color = ConsoleColor.Gray; break;
case LogSeverity.Debug: default: color = ConsoleColor.DarkGray; break;
}
//Exception
string exMessage;
Exception ex = e.Exception;
if (ex != null)
{
while (ex is AggregateException && ex.InnerException != null)
ex = ex.InnerException;
exMessage = ex.Message;
}
else
exMessage = null;
//Source
string sourceName = e.Source?.ToString();
//Text
string text;
if (e.Message == null)
{
text = exMessage ?? "";
exMessage = null;
}
else
text = e.Message;
//Build message
StringBuilder builder = new StringBuilder(text.Length + (sourceName?.Length ?? 0) + (exMessage?.Length ?? 0) + 5);
if (sourceName != null)
{
builder.Append('[');
builder.Append(sourceName);
builder.Append("] ");
}
for (int i = 0; i < text.Length; i++)
{
//Strip control chars
char c = text[i];
if (!char.IsControl(c))
builder.Append(c);
}
if (exMessage != null)
{
builder.Append(": ");
builder.Append(exMessage);
}
text = builder.ToString();
Console.ForegroundColor = color;
Console.WriteLine(text);
}
}
}
Issue Analytics
- State:
- Created 7 years ago
- Comments:9 (1 by maintainers)
Top Results From Across the Web
WebSocketClient's KeepAliveInterval can't be disabled. #60
The way I worked around the issue on Windows for now, is by setting the global Keep-alive Interval in the registry to something...
Read more >c# - .NET WebSockets forcibly closed despite keep-alive ...
We have written a simple WebSocket client using System.Net.WebSockets. The KeepAliveInterval on the ClientWebSocket is set to 30 seconds.
Read more >WebSockets support in ASP.NET Core
This article explains how to get started with WebSockets in ASP.NET Core. WebSocket (RFC 6455) is a protocol that enables two-way persistent ...
Read more >Client WebSocket disconnects when browser is minimized ...
1. disable the feature "Intensive throttling of Javascript timer wake ups" in Chrome or, 2. change the web-transport inactive-timeout in the ...
Read more >API Gateway websockets don't stay alive
My websocket connection works fine until the keepalive timeout triggers on the client, and then it closes despite messages being sent successfully in...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The way I worked around the issue on Windows for now, is by setting the global Keep-alive Interval in the registry to something really large.
HKLM:\Software\Microsoft\WebSocket\KeepaliveInterval
It’s should be a DWORD, if it does not exist already.
This will affect anything that uses the global setting and does not have it’s own setting. (All .NET Core WebSockets currently)
I found this in an msdn page:
This fix is live.