Perform cleanup when starting a Lavalink connection throws
Created by: uwx
Summary
Fixes #321 (closed): LavalinkNodeConnection is cached before a successful connection is made.
Details
I use a try-catch block instead of just moving the cache code down to avoid non-deterministic behavior where Con_Disconnected could be fired without the connection being in the cache. If this is not a problem in a real-world scenario, please close this PR and just move this.ConnectedNodes[con.NodeEndpoint] = con;
down a line.
Changes proposed
- Catch exceptions thrown by LavalinkNodeConnection.StartAsync, remove the connection from the cache, and rethrow.
Notes
As always, this one goes untested, in the hopes that I didn't overlook anything (again).