Skip to content

Commit c5d95c1

Browse files
authored
Improve server status ping sent to start after connection container is ready (#2070)
* Improve server status ping sent to start after connection container is ready * fix tests
1 parent 10fbbcd commit c5d95c1

File tree

4 files changed

+13
-6
lines changed

4 files changed

+13
-6
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -714,7 +714,7 @@ private async Task KeepAliveAsync(TimerAwaitable timer)
714714

715715
while (await timer)
716716
{
717-
if (Stopwatch.GetTimestamp() - Interlocked.Read(ref _lastReceiveTimestamp) > DefaultServiceTimeoutTicks)
717+
if (!Debugger.IsAttached && Stopwatch.GetTimestamp() - Interlocked.Read(ref _lastReceiveTimestamp) > DefaultServiceTimeoutTicks)
718718
{
719719
Log.ServiceTimeout(Logger, _endpointName, DefaultServiceTimeout, ConnectionId);
720720
await StopAsync();

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ protected ServiceConnectionContainerBase(IServiceConnectionFactory serviceConnec
159159
// when server connection count is specified to 0, the app server only handle negotiate requests
160160
if (initial.Count > 0)
161161
{
162-
_statusPing.Start();
162+
_ = StartStatusPing();
163163
}
164164

165165
_serversPing = new CustomizedPingTimer(Logger, Constants.CustomizedPingTimer.Servers, WriteServersPingAsync, Constants.Periods.DefaultServersPingInterval, Constants.Periods.DefaultServersPingInterval);
@@ -420,6 +420,12 @@ protected async Task RemoveConnectionAsync(IServiceConnection c, GracefulShutdow
420420
Log.TimeoutWaitingForFinAck(Logger, retry);
421421
}
422422

423+
private async Task StartStatusPing()
424+
{
425+
await this.ConnectionInitializedTask.ConfigureAwait(false);
426+
_statusPing.Start();
427+
}
428+
423429
private async Task WriteMessageAsync(ServiceMessage serviceMessage)
424430
{
425431
var connection = SelectConnection(serviceMessage);

test/Microsoft.Azure.SignalR.Tests/ServiceConnectionContainerBaseTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public async Task TestServersPing(int startCount, int stopCount, int expectedWar
5050
logger: loggerFactory.CreateLogger<TestServiceConnectionContainer>());
5151

5252
await container.StartAsync();
53-
53+
await container.ConnectionInitializedTask;
5454
var tasks = new List<Task>();
5555

5656
while (startCount > 0)
@@ -111,6 +111,7 @@ public async Task TestServersPingWorkSecondTime(int firstStart, int firstStop, i
111111
logger: loggerFactory.CreateLogger<TestServiceConnectionContainer>());
112112

113113
await container.StartAsync();
114+
await container.ConnectionInitializedTask;
114115

115116
var tasks = new List<Task>();
116117

test/Microsoft.Azure.SignalR.Tests/ServiceLifetimeManagerFacts.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,16 +141,16 @@ public async void ServiceLifetimeManagerIntegrationTest(string methodName, Type
141141

142142
var invokeTask = InvokeMethod(serviceLifetimeManager, methodName);
143143

144+
var message = await task.OrTimeout();
145+
144146
if (typeof(IAckableMessage).IsAssignableFrom(messageType))
145147
{
146-
await proxy.WriteMessageAsync(new AckMessage(1, (int)AckStatus.Ok));
148+
await proxy.WriteMessageAsync(new AckMessage((message as IAckableMessage).AckId, (int)AckStatus.Ok));
147149
}
148150

149151
// Need to return in time, or it indicate a timeout when sending ack-able messages.
150152
await invokeTask.OrTimeout();
151153

152-
var message = await task.OrTimeout();
153-
154154
VerifyServiceMessage(methodName, message);
155155
}
156156

0 commit comments

Comments
 (0)