Throw if SocketAutoReconnect is set to false
Created by: JulianusIV
Summary
When calling LavalinkExtension.ConnectAsync() with no running Lavalink server, a WebSocketException gets logged, and after a few reconnect attempts it throws (after approximately >3 minutes). However when setting SocketAutoReconnect = false in the Configuration the exception never gets thrown.
Details
If SocketAutoReconnect is set to false the method should throw at the first connection failure. Alternatively it could be useful to be able to set a seperate retry property or have an overload with a flag to set if the method should retry the connection or throw after the first one.
Here is also the stack trace of the exception:
[2021-05-22 18:48:07 +00:00] [401 /LavalinkConn] [Crit ] Failed to connect to Lavalink.
System.Net.WebSockets.WebSocketException (0x80004005): Unable to connect to the remote server
---> System.Net.Http.HttpRequestException: Connection refused
---> System.Net.Sockets.SocketException (111): Connection refused
at System.Net.Http.ConnectHelper.ConnectAsync(String host, Int32 port, CancellationToken cancellationToken)
--- End of inner exception stack trace ---
at System.Net.Http.ConnectHelper.ConnectAsync(String host, Int32 port, CancellationToken cancellationToken)
at System.Net.Http.HttpConnectionPool.ConnectAsync(HttpRequestMessage request, Boolean allowHttp2, CancellationToken cancellationToken)
at System.Net.Http.HttpConnectionPool.CreateHttp11ConnectionAsync(HttpRequestMessage request, CancellationToken cancellationToken)
at System.Net.Http.HttpConnectionPool.GetHttpConnectionAsync(HttpRequestMessage request, CancellationToken cancellationToken)
at System.Net.Http.HttpConnectionPool.SendWithRetryAsync(HttpRequestMessage request, Boolean doRequestAuth, CancellationToken cancellationToken)
at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
at System.Net.WebSockets.WebSocketHandle.ConnectAsyncCore(Uri uri, CancellationToken cancellationToken, ClientWebSocketOptions options)
at System.Net.WebSockets.WebSocketHandle.ConnectAsyncCore(Uri uri, CancellationToken cancellationToken, ClientWebSocketOptions options)
at System.Net.WebSockets.ClientWebSocket.ConnectAsyncCore(Uri uri, CancellationToken cancellationToken)
at DSharpPlus.Net.WebSocket.WebSocketClient.ConnectAsync(Uri uri)
at DSharpPlus.Lavalink.LavalinkNodeConnection.StartAsync()
Exception thrown: 'System.Net.WebSockets.WebSocketException' in System.Private.CoreLib.dll
Notes
After looking at the library the theoretical fix should be just to check the SocketAutoReconnect flag additionally to the backoff when catching an exception.