Skip to content

Commit 521b001

Browse files
authored
Thread safe on scale status. (#1596) (#1597)
1 parent 6e304bb commit 521b001

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

src/Microsoft.Azure.SignalR.Common/Endpoints/HubServiceEndpoint.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) Microsoft. All rights reserved.
22
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
33

4+
using System;
45
using System.Threading;
56
using System.Threading.Tasks;
67

@@ -11,7 +12,6 @@ internal class HubServiceEndpoint : ServiceEndpoint
1112
private readonly ServiceEndpoint _endpoint;
1213
private readonly long _uniqueIndex;
1314
private static long s_currentIndex;
14-
private static bool _pendingReload;
1515
private TaskCompletionSource<bool> _scaleTcs;
1616

1717
public HubServiceEndpoint(
@@ -23,7 +23,6 @@ ServiceEndpoint endpoint
2323
Hub = hub;
2424
Provider = provider;
2525
_endpoint = endpoint;
26-
_pendingReload = endpoint.PendingReload;
2726
_scaleTcs = endpoint.PendingReload ? new TaskCompletionSource<bool>(TaskCreationOptions.RunContinuationsAsynchronously) : null;
2827
_uniqueIndex = Interlocked.Increment(ref s_currentIndex);
2928
}
@@ -43,14 +42,12 @@ ServiceEndpoint endpoint
4342

4443
public void CompleteScale()
4544
{
46-
_pendingReload = false;
4745
_scaleTcs?.TrySetResult(true);
4846
}
4947

5048
// When remove an existing HubServiceEndpoint.
5149
public void ResetScale()
5250
{
53-
_pendingReload = true;
5451
_scaleTcs = new TaskCompletionSource<bool>(TaskCreationOptions.RunContinuationsAsynchronously);
5552
}
5653

@@ -61,6 +58,7 @@ public override string ToString()
6158
return base.ToString() + $"(hub={Hub})";
6259
}
6360

64-
internal override bool PendingReload => _pendingReload;
61+
// Value here is not accurate.
62+
internal override bool PendingReload => throw new NotSupportedException();
6563
}
6664
}

src/Microsoft.Azure.SignalR.Common/ServiceConnections/MultiEndpointServiceConnectionContainer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ private void OnAdd(HubServiceEndpoint endpoint)
252252

253253
private async Task AddHubServiceEndpointAsync(HubServiceEndpoint endpoint)
254254
{
255-
if (!endpoint.PendingReload)
255+
if (endpoint.ScaleTask.IsCompleted)
256256
{
257257
UpdateEndpointsStore(endpoint, ScaleOperation.Add);
258258
return;
@@ -296,7 +296,7 @@ private void OnRemove(HubServiceEndpoint endpoint)
296296

297297
private async Task RemoveHubServiceEndpointAsync(HubServiceEndpoint endpoint)
298298
{
299-
if (!endpoint.PendingReload)
299+
if (endpoint.ScaleTask.IsCompleted)
300300
{
301301
UpdateEndpointsStore(endpoint, ScaleOperation.Remove);
302302
return;

0 commit comments

Comments
 (0)