diff --git a/src/Microsoft.AspNetCore.SignalR.Core/HubEndPoint.cs b/src/Microsoft.AspNetCore.SignalR.Core/HubEndPoint.cs index 653fae4c8f..fedc06fa1d 100644 --- a/src/Microsoft.AspNetCore.SignalR.Core/HubEndPoint.cs +++ b/src/Microsoft.AspNetCore.SignalR.Core/HubEndPoint.cs @@ -30,7 +30,6 @@ namespace Microsoft.AspNetCore.SignalR { private static readonly Base64Encoder Base64Encoder = new Base64Encoder(); private static readonly PassThroughEncoder PassThroughEncoder = new PassThroughEncoder(); - private static readonly TimeSpan NegotiateTimeout = TimeSpan.FromSeconds(5); private readonly Dictionary _methods = new Dictionary(StringComparer.OrdinalIgnoreCase); @@ -39,7 +38,7 @@ namespace Microsoft.AspNetCore.SignalR private readonly ILogger> _logger; private readonly IServiceScopeFactory _serviceScopeFactory; private readonly IHubProtocolResolver _protocolResolver; - private readonly IOptions _hubOptions; + private readonly HubOptions _hubOptions; private readonly IUserIdProvider _userIdProvider; public HubEndPoint(HubLifetimeManager lifetimeManager, @@ -53,7 +52,7 @@ namespace Microsoft.AspNetCore.SignalR _protocolResolver = protocolResolver; _lifetimeManager = lifetimeManager; _hubContext = hubContext; - _hubOptions = hubOptions; + _hubOptions = hubOptions.Value; _logger = logger; _serviceScopeFactory = serviceScopeFactory; _userIdProvider = userIdProvider; @@ -131,7 +130,7 @@ namespace Microsoft.AspNetCore.SignalR { using (var cts = new CancellationTokenSource()) { - cts.CancelAfter(NegotiateTimeout); + cts.CancelAfter(_hubOptions.NegotiateTimeout); while (await connection.Input.WaitToReadAsync(cts.Token)) { while (connection.Input.TryRead(out var buffer)) diff --git a/src/Microsoft.AspNetCore.SignalR.Core/HubOptions.cs b/src/Microsoft.AspNetCore.SignalR.Core/HubOptions.cs index f652ea6755..1ca0415e8e 100644 --- a/src/Microsoft.AspNetCore.SignalR.Core/HubOptions.cs +++ b/src/Microsoft.AspNetCore.SignalR.Core/HubOptions.cs @@ -1,6 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using Microsoft.AspNetCore.SignalR.Internal.Protocol; using MsgPack.Serialization; using Newtonsoft.Json; @@ -11,5 +12,6 @@ namespace Microsoft.AspNetCore.SignalR { public JsonSerializerSettings JsonSerializerSettings { get; set; } = JsonHubProtocol.CreateDefaultSerializerSettings(); public SerializationContext MessagePackSerializationContext { get; set; } = MessagePackHubProtocol.CreateDefaultSerializationContext(); + public TimeSpan NegotiateTimeout { get; set; } = TimeSpan.FromSeconds(5); } } diff --git a/test/Microsoft.AspNetCore.SignalR.Tests/HubEndpointTests.cs b/test/Microsoft.AspNetCore.SignalR.Tests/HubEndpointTests.cs index b147de72a7..e5c8e0cb6a 100644 --- a/test/Microsoft.AspNetCore.SignalR.Tests/HubEndpointTests.cs +++ b/test/Microsoft.AspNetCore.SignalR.Tests/HubEndpointTests.cs @@ -274,7 +274,13 @@ namespace Microsoft.AspNetCore.SignalR.Tests [Fact] public async Task NegotiateTimesOut() { - var serviceProvider = CreateServiceProvider(); + var serviceProvider = CreateServiceProvider(services => + { + services.Configure(hubOptions => + { + hubOptions.NegotiateTimeout = TimeSpan.FromMilliseconds(5); + }); + }); var endPoint = serviceProvider.GetService>(); using (var client = new TestClient()) @@ -282,7 +288,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests // TestClient automatically writes negotiate, for this test we want to assume negotiate never gets sent client.Connection.Transport.In.TryRead(out var item); - await endPoint.OnConnectedAsync(client.Connection).OrTimeout(TimeSpan.FromSeconds(10)); + await endPoint.OnConnectedAsync(client.Connection).OrTimeout(); } }