Add negotiate timeout option to hub options (#1003)
This commit is contained in:
parent
de535422d7
commit
8701baf73d
|
|
@ -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<string, HubMethodDescriptor> _methods = new Dictionary<string, HubMethodDescriptor>(StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
|
|
@ -39,7 +38,7 @@ namespace Microsoft.AspNetCore.SignalR
|
|||
private readonly ILogger<HubEndPoint<THub>> _logger;
|
||||
private readonly IServiceScopeFactory _serviceScopeFactory;
|
||||
private readonly IHubProtocolResolver _protocolResolver;
|
||||
private readonly IOptions<HubOptions> _hubOptions;
|
||||
private readonly HubOptions _hubOptions;
|
||||
private readonly IUserIdProvider _userIdProvider;
|
||||
|
||||
public HubEndPoint(HubLifetimeManager<THub> 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))
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 =>
|
||||
{
|
||||
hubOptions.NegotiateTimeout = TimeSpan.FromMilliseconds(5);
|
||||
});
|
||||
});
|
||||
var endPoint = serviceProvider.GetService<HubEndPoint<SimpleHub>>();
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue