-
Notifications
You must be signed in to change notification settings - Fork 108
Fix client invocation bug with multiple endpoints #2154
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| // Copyright (c) Microsoft. All rights reserved. | ||
| // Copyright (c) Microsoft. All rights reserved. | ||
| // Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
|
||
| using System; | ||
|
|
@@ -9,6 +9,7 @@ | |
| using System.Threading; | ||
| using System.Threading.Tasks; | ||
|
|
||
| using Microsoft.AspNetCore.SignalR.Protocol; | ||
| using Microsoft.Azure.SignalR.Common; | ||
| using Microsoft.Azure.SignalR.Protocol; | ||
| using Microsoft.Extensions.Logging; | ||
|
|
@@ -21,11 +22,13 @@ namespace Microsoft.Azure.SignalR; | |
| internal class MultiEndpointMessageWriter : IServiceMessageWriter, IPresenceManager | ||
| { | ||
| private readonly ILogger _logger; | ||
| private readonly IClientInvocationManager _clientInvocationManager; | ||
|
|
||
| internal HubServiceEndpoint[] TargetEndpoints { get; } | ||
|
|
||
| public MultiEndpointMessageWriter(IReadOnlyCollection<ServiceEndpoint> targetEndpoints, ILoggerFactory loggerFactory) | ||
| public MultiEndpointMessageWriter(IReadOnlyCollection<ServiceEndpoint> targetEndpoints, IClientInvocationManager invocationManager, ILoggerFactory loggerFactory) | ||
| { | ||
| _clientInvocationManager = invocationManager; | ||
| _logger = loggerFactory.CreateLogger<MultiEndpointMessageWriter>(); | ||
| var normalized = new List<HubServiceEndpoint>(); | ||
| if (targetEndpoints != null) | ||
|
|
@@ -52,6 +55,19 @@ public MultiEndpointMessageWriter(IReadOnlyCollection<ServiceEndpoint> targetEnd | |
|
|
||
| public Task WriteAsync(ServiceMessage serviceMessage) | ||
| { | ||
| if (serviceMessage is ClientInvocationMessage invocationMessage) | ||
| { | ||
| // Accroding to target endpoints in method `WriteMultiEndpointMessageAsync` | ||
| _clientInvocationManager.Caller.SetAckNumber(invocationMessage.InvocationId, TargetEndpoints.Length); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. when There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. class There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we still need to SetAck if Length == 0? |
||
| if (TargetEndpoints.Length == 0) | ||
| { | ||
| _clientInvocationManager.Caller.TryCompleteResult( | ||
| invocationMessage.ConnectionId, | ||
| CompletionMessage.WithError(invocationMessage.InvocationId, "No available endpoint to send invocation message.") | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| return WriteMultiEndpointMessageAsync(serviceMessage, connection => connection.WriteAsync(serviceMessage)); | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -129,8 +129,14 @@ public override async Task<T> InvokeConnectionAsync<T>(string connectionId, stri | |
|
|
||
| var invocationId = _clientInvocationManager.Caller.GenerateInvocationId(connectionId); | ||
| var message = AppendMessageTracingId(new ClientInvocationMessage(invocationId, connectionId, _callerId, SerializeAllProtocols(methodName, args, invocationId))); | ||
| await WriteAsync(message); | ||
| // The ack number of invocation will be set inside `WriteAsync`. So adding invocation should be first. | ||
| var task = _clientInvocationManager.Caller.AddInvocation<T>(_hub, connectionId, invocationId, cancellationToken); | ||
| await WriteAsync(message); | ||
| if (ServiceConnectionContainer is not MultiEndpointServiceConnectionContainer) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sounds tricky, a ServiceLifttimeManager should not have knowledge of what the container type is, it looks like a strong assumption and is fragile. What if we later change to use other container? |
||
| { | ||
| // `WriteAsync` in test class `TestServiceConnectionHandler` does not set ack number. Set the number manually. | ||
| _clientInvocationManager.Caller.SetAckNumber(invocationId, 1); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we don't want such logic spread into multiple layers, choose one place for such logic |
||
| } | ||
|
|
||
| // Exception handling follows https://source.dot.net/#Microsoft.AspNetCore.SignalR.Core/DefaultHubLifetimeManager.cs,349 | ||
| try | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.