Skip to content

Commit

Permalink
Merge pull request #1825 from terencefan/release-1.21.6
Browse files Browse the repository at this point in the history
Release 1.21.6
  • Loading branch information
terencefan authored Aug 30, 2023
2 parents 33d3e47 + c4a5877 commit d5dff37
Show file tree
Hide file tree
Showing 11 changed files with 121 additions and 47 deletions.
3 changes: 2 additions & 1 deletion specs/ClientInvocation.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,5 @@ Basically the process is similar and the major different is that service underst
>
> * Service cached pending invocations for at most __10 minutes__ for memory concerns and will notify server when timeout.
> * Serverless is __NOT__ supporeted in the first stage.
> * ASPNET SignalR is __NOT__ supported.
> * ASPNET SignalR is __NOT__ supported.
> * Sharding is __NOT__ supported. Please use [Geo-Replication](https://learn.microsoft.com/azure/azure-signalr/howto-enable-geo-replication) for combined client invocation and large scale scenarios.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ internal class AadAccessKey : AccessKey

internal const int GetTokenMaxRetryTimes = 3;

internal static readonly TimeSpan AuthorizeTimeout = TimeSpan.FromSeconds(10);
internal static readonly TimeSpan AuthorizeTimeout = TimeSpan.FromSeconds(100);

private const string DefaultScope = "https://signalr.azure.com/.default";

Expand Down
58 changes: 32 additions & 26 deletions src/Microsoft.Azure.SignalR.Common/Logging/MessageLog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,31 @@ namespace Microsoft.Azure.SignalR
{
internal static class MessageLog
{
public const string StartToBroadcastMessageTemplate = "Start to broadcast message {0}.";
public const string StartToBroadcastMessageWithExcludedConnectionTemplate = "Start to broadcast message {0} except for {1} connections {2}.";
public const string StartToSendMessageToConnectionsTemplate = "Start to send message {0} to {1} connections {2}.";
public const string StartToSendMessageToConnectionTemplate = "Start to send message {0} to connection {1}.";
public const string StartToBroadcastMessageToGroupTemplate = "Start to broadcast message {0} to group {1}.";
public const string StartToBroadcastMessageToGroupWithExcludedConnectionsTemplate = "Start to broadcast message {0} to group {1} except for {2} connections {3}.";
public const string StartToBroadcastMessageToGroupsTemplate = "Start to broadcast message {0} to {1} groups {2}.";
public const string StartToSendMessageToUserTemplate = "Start to send message {0} to user {1}.";
public const string StartToSendMessageToUsersTemplate = "Start to send message {0} to {1} users {2}.";
public const string StartToAddConnectionToGroupTemplate = "Start to send message {0} to add connection {1} to group {2}.";
public const string StartToRemoveConnectionFromGroupTemplate = "Start to send message {0} to remove connection {1} from group {2}.";
public const string StartToAddUserToGroupTemplate = "Start to send message {0} to add user {1} to group {2}.";
public const string StartToAddUserToGroupWithTtlTemplate = "Start to send message {0} to add user {1} to group {2} with TTL {3} seconds.";
public const string StartToRemoveUserFromGroupTemplate = "Start to send message {0} to remove user {1} from group {2}.";
public const string StartToRemoveUserFromAllGroupsTemplate = "Start to send message {0} to remove user {1} from all groups.";
public const string StartToRemoveConnectionFromAllGroupsTemplate = "Start to send message {0} to remove connection {1} from all groups.";
public const string StartToCheckIfUserInGroupTemplate = "Start to send message {0} to check if user {1} in group {2}.";
public const string FailedToSendMessageTemplate = "Failed to send message {0}.";
public const string SucceededToSendMessageTemplate = "Succeeded to send message {0}.";

public const string StartToBroadcastMessageTemplate = "Start to broadcast message {tracingId}.";
public const string StartToBroadcastMessageWithExcludedConnectionTemplate = "Start to broadcast message {tracingId} except for {excludedCount} connections {excludedList}.";
public const string StartToSendMessageToConnectionsTemplate = "Start to send message {tracingId} to {connectionsCount} connections {connectionsList}.";
public const string StartToSendMessageToConnectionTemplate = "Start to send message {tracingId} to connection {connectionId}.";
public const string StartToBroadcastMessageToGroupTemplate = "Start to broadcast message {tracingId} to group {group}.";
public const string StartToBroadcastMessageToGroupWithExcludedConnectionsTemplate = "Start to broadcast message {tracingId} to group {group} except for {excludedCount} connections {connectionsList}.";
public const string StartToBroadcastMessageToGroupsTemplate = "Start to broadcast message {tracingId} to {groupsCount} groups {groupsList}.";
public const string StartToSendMessageToUserTemplate = "Start to send message {tracingId} to user {userId}.";
public const string StartToSendMessageToUsersTemplate = "Start to send message {tracingId} to {usersCount} users {usersList}.";
public const string StartToAddConnectionToGroupTemplate = "Start to send message {tracingId} to add connection {connectionId} to group {group}.";
public const string StartToRemoveConnectionFromGroupTemplate = "Start to send message {tracingId} to remove connection {connectionId} from group {group}.";
public const string StartToAddUserToGroupTemplate = "Start to send message {tracingId} to add user {userId} to group {group}.";
public const string StartToAddUserToGroupWithTtlTemplate = "Start to send message {tracingId} to add user {userId} to group {group} with TTL {timeToLive} seconds.";
public const string StartToRemoveUserFromGroupTemplate = "Start to send message {tracingId} to remove user {userId} from group {group}.";
public const string StartToRemoveUserFromAllGroupsTemplate = "Start to send message {tracingId} to remove user {userId} from all groups.";
public const string StartToRemoveConnectionFromAllGroupsTemplate = "Start to send message {tracingId} to remove connection {connectionId} from all groups.";
public const string StartToCheckIfUserInGroupTemplate = "Start to send message {tracingId} to check if user {userId} in group {group}.";
public const string FailedToSendMessageTemplate = "Failed to send message {tracingId}.";
public const string SucceededToSendMessageTemplate = "Succeeded to send message {tracingId}.";
public const string ReceivedMessageFromClientConnectionTemplate = "Received message {tracingId} from client connection {connectionId}.";
public const string StartToSendMessageToCloseConnectionTemplate = "Start to send message {tracingId} to close connection {connectionId} for reason: '{reason}'.";
public const string StartToSendMessageToCheckConnectionTemplate = "Start to send message {tracingId} to check if connection {connectionId} exists.";
public const string StartToSendMessageToCheckIfUserExistsTemplate = "Start to send message {tracingId} to check if user {userId} exists.";
public const string StartToSendMessageToCheckIfGroupExistsTemplate = "Start to send message {tracingId} to check if group {group} exists.";

private static readonly Action<ILogger, ulong?, Exception> _startToBroadcastMessage =
LoggerMessage.Define<ulong?>(
LogLevel.Information,
Expand Down Expand Up @@ -141,7 +146,7 @@ internal static class MessageLog
LoggerMessage.Define<ulong?, string>(
LogLevel.Information,
new EventId(120, "RecieveMessageFromService"),
"Received message {tracingId} from client connection {connectionId}.");
ReceivedMessageFromClientConnectionTemplate);

private static readonly Action<ILogger, ulong?, string, string, Exception> _startToCheckIfUserInGroup =
LoggerMessage.Define<ulong?, string, string>(
Expand All @@ -153,24 +158,25 @@ internal static class MessageLog
LoggerMessage.Define<ulong?, string, string>(
LogLevel.Information,
new EventId(140, "StartToCloseConnection"),
"Start to send message {tracingId} to close connection {connectionId} for reason: '{reason}'.");
StartToSendMessageToCloseConnectionTemplate);

private static readonly Action<ILogger, ulong?, string, Exception> _startToCheckIfConnectionExists = LoggerMessage.Define<ulong?, string>(
private static readonly Action<ILogger, ulong?, string, Exception> _startToCheckIfConnectionExists =
LoggerMessage.Define<ulong?, string>(
LogLevel.Information,
new EventId(150, "StartToCheckIfConnectionExists"),
"Start to send message {tracingId} to check if connection {connectionId} exists.");
StartToSendMessageToCheckConnectionTemplate);

private static readonly Action<ILogger, ulong?, string, Exception> _startToCheckIfUserExists =
LoggerMessage.Define<ulong?, string>(
LogLevel.Information,
new EventId(160, "StartToCheckIfUserExists"),
"Start to send message {tracingId} to check if user {userId} exists.");
StartToSendMessageToCheckIfUserExistsTemplate);

private static readonly Action<ILogger, ulong?, string, Exception> _startToCheckIfGroupExists =
LoggerMessage.Define<ulong?, string>(
LogLevel.Information,
new EventId(170, "StartToCheckIfGroupExists"),
"Start to send message {tracingId} to check if group {group} exists.");
StartToSendMessageToCheckIfGroupExistsTemplate);

public static void ReceiveMessageFromService(ILogger logger, ConnectionDataMessage message)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,10 @@ protected Task OnServiceErrorAsync(ServiceErrorMessage serviceErrorMessage)

protected virtual Task OnPingMessageAsync(PingMessage pingMessage)
{
if (RuntimeServicePingMessage.IsEchoMessage(pingMessage))
{
return WriteAsync(pingMessage);
}
if (RuntimeServicePingMessage.TryGetOffline(pingMessage, out var instanceId))
{
Log.ReceivedInstanceOfflinePing(Logger, instanceId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace Microsoft.Azure.SignalR
{
internal static class RuntimeServicePingMessage
{
private const string EchoKey = "echo";
private const string OfflineKey = "offline";
private const string TargetKey = "target";
private const string StatusKey = "status";
Expand Down Expand Up @@ -52,6 +53,11 @@ internal static class RuntimeServicePingMessage
private static readonly ServicePingMessage ServersTag =
new ServicePingMessage { Messages = new[] { ServersKey, string.Empty } };

public static bool IsEchoMessage(this ServicePingMessage ping)
{
return TryGetValue(ping, EchoKey, out _);
}

public static bool TryGetMessageLogEnableFlag(this ServicePingMessage ping, out bool enableMessageLog)
{
if (TryGetValue(ping, DiagnosticLogsMessagingTypeKey, out var value))
Expand Down
5 changes: 5 additions & 0 deletions src/Microsoft.Azure.SignalR.Protocols/ServiceMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,11 @@ public class HandshakeResponseMessage : ExtensibleServiceMessage
/// </summary>
public string ErrorMessage { get; set; }

/// <summary>
/// Gets or sets the id of this connection.
/// </summary>
public string ConnectionId { get; set; }

/// <summary>
/// Initializes a new instance of the <see cref="HandshakeResponseMessage"/> class.
/// </summary>
Expand Down
7 changes: 6 additions & 1 deletion src/Microsoft.Azure.SignalR.Protocols/ServiceProtocol.cs
Original file line number Diff line number Diff line change
Expand Up @@ -319,10 +319,11 @@ private static void WriteHandshakeRequestMessage(ref MessagePackWriter writer, H

private static void WriteHandshakeResponseMessage(ref MessagePackWriter writer, HandshakeResponseMessage message)
{
writer.WriteArrayHeader(3);
writer.WriteArrayHeader(4);
writer.Write(ServiceProtocolConstants.HandshakeResponseType);
writer.Write(message.ErrorMessage);
message.WriteExtensionMembers(ref writer);
writer.Write(message.ConnectionId);
}

private static void WriteAccessKeyRequestMessage(ref MessagePackWriter writer, AccessKeyRequestMessage message)
Expand Down Expand Up @@ -800,6 +801,10 @@ private static HandshakeResponseMessage CreateHandshakeResponseMessage(ref Messa
{
result.ReadExtensionMembers(ref reader);
}
if (arrayLength >= 4)
{
result.ConnectionId = ReadString(ref reader, "connectionId");
}
return result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ private bool HandshakeRequestMessagesEqual(HandshakeRequestMessage x, HandshakeR

private bool HandshakeResponseMessagesEqual(HandshakeResponseMessage x, HandshakeResponseMessage y)
{
return StringEqual(x.ErrorMessage, y.ErrorMessage);
return StringEqual(x.ErrorMessage, y.ErrorMessage) &&
StringEqual(x.ConnectionId, y.ConnectionId);
}

private bool AccessKeyRequestMessageEqual(AccessKeyRequestMessage x, AccessKeyRequestMessage y)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,18 @@ public static IEnumerable<object[]> TestParseOldData
name: "HandshakeResponse_NoOptionalField",
message: new HandshakeResponseMessage(),
binary: "kgKg"),
new ProtocolTestData(
name: "HandshakeResponse_NoConnectionId",
message: new HandshakeResponseMessage(),
binary: "kwKggA=="),
new ProtocolTestData(
name: "HandshakeResponseWithError_NoOptionalField",
message: new HandshakeResponseMessage("Version mismatch."),
binary: "kgKxVmVyc2lvbiBtaXNtYXRjaC4="),
new ProtocolTestData(
name: "HandshakeResponseWithError_NoConnectionId",
message: new HandshakeResponseMessage("Version mismatch."),
binary: "kwKxVmVyc2lvbiBtaXNtYXRjaC6A"),
new ProtocolTestData(
name: "OpenConnection_NoOptionalField",
message: new OpenConnectionMessage("conn1", null),
Expand Down Expand Up @@ -280,11 +288,15 @@ public static IEnumerable<object[]> TestParseOldData
new ProtocolTestData(
name: "HandshakeResponse",
message: new HandshakeResponseMessage(),
binary: "kwKggA=="),
binary: "lAKggMA="),
new ProtocolTestData(
name: "HandshakeResponseWithError",
message: new HandshakeResponseMessage("Version mismatch."),
binary: "kwKxVmVyc2lvbiBtaXNtYXRjaC6A"),
binary: "lAKxVmVyc2lvbiBtaXNtYXRjaC6AwA=="),
new ProtocolTestData(
name: "HandshakeResponseWithConnectionId",
message: new HandshakeResponseMessage() { ConnectionId = "abc" },
binary: "lAKggKNhYmM="),
new ProtocolTestData(
name: "AccessKeyRequestMessage",
message: new AccessKeyRequestMessage("token"),
Expand Down
Loading

0 comments on commit d5dff37

Please sign in to comment.