Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/SignalR/clients/csharp/Client.Core/src/HubConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,11 @@ private async Task StopAsyncCore(bool disposing)
{
connectionState.Stopping = true;
}
else
{
// Reset StopCts if there isn't an active connection so that the next StartAsync wont immediately fail due to the token being canceled
_state.StopCts = new CancellationTokenSource();
}

if (disposing)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,26 @@ await AsyncUsing(CreateHubConnection(testConnection), async connection =>
});
}

[Fact]
public async Task StopAsyncOnInactiveConnectionDoesNotAffectNextStartAsync()
{
// Regression test:
// If there wasn't an active underlying connection, StopAsync would leave a CTS canceled which would cause the next StartAsync to fail
var testConnection = new TestConnection();
await AsyncUsing(CreateHubConnection(testConnection), async connection =>
{
Assert.Equal(HubConnectionState.Disconnected, connection.State);

await connection.StopAsync().OrTimeout();
Assert.False(testConnection.Disposed.IsCompleted);
Assert.Equal(HubConnectionState.Disconnected, connection.State);

await connection.StartAsync().OrTimeout();
Assert.True(testConnection.Started.IsCompleted);
Assert.Equal(HubConnectionState.Connected, connection.State);
});
}

[Fact]
public async Task CompletingTheTransportSideMarksConnectionAsClosed()
{
Expand Down