Skip to content

Commit

Permalink
fix: Fix race condition
Browse files Browse the repository at this point in the history
  • Loading branch information
angelobreuer committed Aug 21, 2023
1 parent 6a65795 commit 5a8de7b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
3 changes: 1 addition & 2 deletions src/Lavalink4NET.Tests/LavalinkNodeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -545,9 +545,8 @@ public void Complete()
.WaitAsync(_shutdownCancellationTokenSource.Token)
.ConfigureAwait(false);
}
catch (Exception exception)
catch
{
var k = exception;
if (_flushSemaphoreSlim.CurrentCount is 0)
{
_flushSemaphoreSlim.Release();
Expand Down
11 changes: 7 additions & 4 deletions src/Lavalink4NET/LavalinkNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,13 @@ private async Task ReceiveInternalAsync(ClientInformation clientInformation, Can

while (!_shutdownCancellationToken.IsCancellationRequested)
{
if (_readyTaskCompletionSource.Task.IsCompleted)
{
// Initiate reconnect
_readyTaskCompletionSource = new TaskCompletionSource<string>(
creationOptions: TaskCreationOptions.RunContinuationsAsynchronously);
}

var socketOptions = new LavalinkSocketOptions
{
Label = Label,
Expand All @@ -472,10 +479,6 @@ private async Task ReceiveInternalAsync(ClientInformation clientInformation, Can
_ = socket.RunAsync(socketCancellationSource.Token).AsTask();

await ReceiveInternalAsync(socket, cancellationToken).ConfigureAwait(false);

// Initiate reconnect
_readyTaskCompletionSource = new TaskCompletionSource<string>(
creationOptions: TaskCreationOptions.RunContinuationsAsynchronously);
}
}

Expand Down

0 comments on commit 5a8de7b

Please sign in to comment.