Skip to content
This repository was archived by the owner on Dec 18, 2018. It is now read-only.

Commit c1d2024

Browse files
authored
Implement #1156 by having the server send Ping messages (#1161)
1 parent 8bb0efe commit c1d2024

File tree

63 files changed

+1225
-474
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+1225
-474
lines changed

SignalR.sln

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Microsoft Visual Studio Solution File, Format Version 12.00
22
# Visual Studio 15
3-
VisualStudioVersion = 15.0.26923.0
3+
VisualStudioVersion = 15.0.27110.0
44
MinimumVisualStudioVersion = 15.0.26730.03
55
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{DA69F624-5398-4884-87E4-B816698CDE65}"
66
ProjectSection(SolutionItems) = preProject
@@ -56,14 +56,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Signal
5656
EndProject
5757
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.SignalR.Client.TS", "client-ts\Microsoft.AspNetCore.SignalR.Client.TS\Microsoft.AspNetCore.SignalR.Client.TS.csproj", "{333526A4-633B-491A-AC45-CC62A0012D1C}"
5858
EndProject
59-
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Common", "Common", "{6CEC3DC2-5B01-45A8-8F0D-8531315DA90B}"
60-
ProjectSection(SolutionItems) = preProject
61-
test\Common\ChannelExtensions.cs = test\Common\ChannelExtensions.cs
62-
test\Common\ServerFixture.cs = test\Common\ServerFixture.cs
63-
test\Common\TaskExtensions.cs = test\Common\TaskExtensions.cs
64-
test\Common\TestHelpers.cs = test\Common\TestHelpers.cs
65-
EndProjectSection
66-
EndProject
6759
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "client-ts", "client-ts", "{3A76C5A2-79ED-49BC-8BDC-6A3A766FFA1B}"
6860
ProjectSection(SolutionItems) = preProject
6961
client-ts\package.json = client-ts\package.json
@@ -91,7 +83,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Signal
9183
EndProject
9284
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JwtSample", "samples\JwtSample\JwtSample.csproj", "{6A7491D3-3C97-49BD-A71C-433AED657F30}"
9385
EndProject
94-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JwtClientSample", "samples\JwtClientSample\JwtClientSample.csproj", "{1A953296-E869-4DE2-A693-FD5FCDE27057}"
86+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JwtClientSample", "samples\JwtClientSample\JwtClientSample.csproj", "{1A953296-E869-4DE2-A693-FD5FCDE27057}"
87+
EndProject
88+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.AspNetCore.SignalR.Tests.Utils", "test\Microsoft.AspNetCore.SignalR.Tests.Utils\Microsoft.AspNetCore.SignalR.Tests.Utils.csproj", "{0A0A6135-EA24-4307-95C2-CE1B7E164A5E}"
9589
EndProject
9690
Global
9791
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -207,6 +201,10 @@ Global
207201
{1A953296-E869-4DE2-A693-FD5FCDE27057}.Debug|Any CPU.Build.0 = Debug|Any CPU
208202
{1A953296-E869-4DE2-A693-FD5FCDE27057}.Release|Any CPU.ActiveCfg = Release|Any CPU
209203
{1A953296-E869-4DE2-A693-FD5FCDE27057}.Release|Any CPU.Build.0 = Release|Any CPU
204+
{0A0A6135-EA24-4307-95C2-CE1B7E164A5E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
205+
{0A0A6135-EA24-4307-95C2-CE1B7E164A5E}.Debug|Any CPU.Build.0 = Debug|Any CPU
206+
{0A0A6135-EA24-4307-95C2-CE1B7E164A5E}.Release|Any CPU.ActiveCfg = Release|Any CPU
207+
{0A0A6135-EA24-4307-95C2-CE1B7E164A5E}.Release|Any CPU.Build.0 = Release|Any CPU
210208
EndGlobalSection
211209
GlobalSection(SolutionProperties) = preSolution
212210
HideSolutionNode = FALSE
@@ -228,7 +226,6 @@ Global
228226
{354335AB-CEE9-4434-A641-78058F6EFE56} = {DA69F624-5398-4884-87E4-B816698CDE65}
229227
{455B68D2-C5B6-4BF4-A685-964B07AFAAF8} = {6A35B453-52EC-48AF-89CA-D4A69800F131}
230228
{333526A4-633B-491A-AC45-CC62A0012D1C} = {3A76C5A2-79ED-49BC-8BDC-6A3A766FFA1B}
231-
{6CEC3DC2-5B01-45A8-8F0D-8531315DA90B} = {6A35B453-52EC-48AF-89CA-D4A69800F131}
232229
{96771B3F-4D18-41A7-A75B-FF38E76AAC89} = {8A4582C8-DC59-4B61-BCE7-119FBAA99EFB}
233230
{75E342F6-5445-4E7E-9143-6D9AE62C2B1E} = {6A35B453-52EC-48AF-89CA-D4A69800F131}
234231
{F2E4FBD6-9AEA-4A82-BAC9-3FAACA677DF8} = {DA69F624-5398-4884-87E4-B816698CDE65}
@@ -240,6 +237,7 @@ Global
240237
{0B083AE6-86CA-4E0B-AE02-59154D1FD005} = {6A35B453-52EC-48AF-89CA-D4A69800F131}
241238
{6A7491D3-3C97-49BD-A71C-433AED657F30} = {C4BC9889-B49F-41B6-806B-F84941B2549B}
242239
{1A953296-E869-4DE2-A693-FD5FCDE27057} = {C4BC9889-B49F-41B6-806B-F84941B2549B}
240+
{0A0A6135-EA24-4307-95C2-CE1B7E164A5E} = {6A35B453-52EC-48AF-89CA-D4A69800F131}
243241
EndGlobalSection
244242
GlobalSection(ExtensibilityGlobals) = postSolution
245243
SolutionGuid = {7945A4E4-ACDB-4F6E-95CA-6AC6E7C2CD59}

benchmarks/Microsoft.AspNetCore.SignalR.Microbenchmarks/BroadcastBenchmark.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
using System;
2+
using System.Threading;
23
using System.Threading.Channels;
34
using System.Threading.Tasks;
45
using BenchmarkDotNet.Attributes;
56
using Microsoft.AspNetCore.SignalR.Internal.Protocol;
67
using Microsoft.AspNetCore.Sockets;
78
using Microsoft.AspNetCore.Sockets.Internal;
9+
using Microsoft.Extensions.Logging.Abstractions;
810

911
namespace Microsoft.AspNetCore.SignalR.Microbenchmarks
1012
{
@@ -32,7 +34,7 @@ public void GlobalSetup()
3234
var transport = ChannelConnection.Create<byte[]>(input: transportToApplication, output: applicationToTransport);
3335
var connection = new DefaultConnectionContext(Guid.NewGuid().ToString(), transport, application);
3436

35-
_hubLifetimeManager.OnConnectedAsync(new HubConnectionContext(Channel.CreateUnbounded<HubMessage>(), connection)).Wait();
37+
_hubLifetimeManager.OnConnectedAsync(new HubConnectionContext(connection, Timeout.InfiniteTimeSpan, NullLoggerFactory.Instance)).Wait();
3638
}
3739

3840
_hubContext = new HubContext<Hub>(_hubLifetimeManager);

client-ts/package-lock.json

Lines changed: 14 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

samples/SocketsSample/Startup.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

4+
using System;
45
using Microsoft.AspNetCore.Builder;
56
using Microsoft.AspNetCore.Hosting;
67
using Microsoft.Extensions.DependencyInjection;
@@ -17,7 +18,11 @@ public void ConfigureServices(IServiceCollection services)
1718
{
1819
services.AddSockets();
1920

20-
services.AddSignalR();
21+
services.AddSignalR(options =>
22+
{
23+
// Faster pings for testing
24+
options.KeepAliveInterval = TimeSpan.FromSeconds(5);
25+
});
2126
// .AddRedis();
2227

2328
services.AddCors(o =>

samples/SocketsSample/wwwroot/hubs.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!DOCTYPE html>
1+
<!DOCTYPE html>
22
<html>
33
<head>
44
<meta charset="utf-8" />

samples/SocketsSample/wwwroot/sockets.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!DOCTYPE html>
1+
<!DOCTYPE html>
22
<html>
33
<head>
44
<meta charset="utf-8" />
@@ -31,7 +31,7 @@ <h1 id="transportName">Unknown Transport</h1>
3131
document.getElementById('transportName').innerHTML = signalR.TransportType[transportType];
3232

3333
let url = 'http://' + document.location.host + '/chat';
34-
let connection = new signalR.HttpConnection(url, { transport: transportType, logger: new signalR.ConsoleLogger(signalR.LogLevel.Information) });
34+
let connection = new signalR.HttpConnection(url, { transport: transportType, logging: new signalR.ConsoleLogger(signalR.LogLevel.Information) });
3535

3636
connection.onreceive = function(data) {
3737
let child = document.createElement('li');

samples/SocketsSample/wwwroot/streaming.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!DOCTYPE html>
1+
<!DOCTYPE html>
22
<html>
33
<head>
44
<meta charset="utf-8" />
@@ -65,7 +65,7 @@ <h2>Results</h2>
6565
});
6666

6767
click('connectButton', function () {
68-
connection = new signalR.HubConnection('/streaming', { transport: transportType, logger: logger });
68+
connection = new signalR.HubConnection('/streaming', { transport: transportType, logging: logger });
6969

7070
connection.onclose(function () {
7171
channelButton.disabled = true;

specs/HubProtocol.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ Keep alive behavior is achieved via the `Ping` message type. **Either endpoint**
109109

110110
Ping messages do not have any payload, they are completely empty messages (aside from the encoding necessary to identify the message as a `Ping` message).
111111

112+
It is up to the server implementation to decide how frequently (if at all) `Ping` frames are sent. The ASP.NET Core implementation sends `Ping` frames only when using the Server Sent Events and WebSockets transports, at a default interval of 15 seconds (configurable). However, a `Ping` frame is only sent if 15 seconds elapses since the last message was sent. Clients may choose to use the "Ping rate" to provide a timeout for the server connection. Since the Client can expect the server to send `Ping` frames at regular intervals, even when the connection is idle, it can use that to determine if the server has left without closing the connection. The ASP.NET Core implementation (both JavaScript and C#) use a default timeout window of 30 seconds, which is twice the server ping rate interval.
113+
112114
## Example
113115

114116
Consider the following C# methods

src/Microsoft.AspNetCore.SignalR.Core/DefaultHubLifetimeManager.cs

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) .NET Foundation. All rights reserved.
1+
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using System;
@@ -86,7 +86,7 @@ private Task InvokeAllWhere(string methodName, object[] args, Func<HubConnection
8686
continue;
8787
}
8888

89-
tasks.Add(WriteAsync(connection, message));
89+
tasks.Add(connection.WriteAsync(message));
9090
}
9191

9292
return Task.WhenAll(tasks);
@@ -108,7 +108,7 @@ public override Task InvokeConnectionAsync(string connectionId, string methodNam
108108

109109
var message = CreateInvocationMessage(methodName, args);
110110

111-
return WriteAsync(connection, message);
111+
return connection.WriteAsync(message);
112112
}
113113

114114
public override Task InvokeGroupAsync(string groupName, string methodName, object[] args)
@@ -122,7 +122,7 @@ public override Task InvokeGroupAsync(string groupName, string methodName, objec
122122
if (group != null)
123123
{
124124
var message = CreateInvocationMessage(methodName, args);
125-
var tasks = group.Values.Select(c => WriteAsync(c, message));
125+
var tasks = group.Values.Select(c => c.WriteAsync(message));
126126
return Task.WhenAll(tasks);
127127
}
128128

@@ -153,17 +153,6 @@ public override Task OnDisconnectedAsync(HubConnectionContext connection)
153153
return Task.CompletedTask;
154154
}
155155

156-
private async Task WriteAsync(HubConnectionContext connection, HubInvocationMessage hubMessage)
157-
{
158-
while (await connection.Output.WaitToWriteAsync())
159-
{
160-
if (connection.Output.TryWrite(hubMessage))
161-
{
162-
break;
163-
}
164-
}
165-
}
166-
167156
private string GetInvocationId()
168157
{
169158
var invocationId = Interlocked.Increment(ref _nextInvocationId);

src/Microsoft.AspNetCore.SignalR.Core/Features/IHubFeature.cs

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)