diff --git a/eng/Versions.props b/eng/Versions.props index 184db4c0eb7f..5b70771aed07 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -318,7 +318,7 @@ 4.17.0 1.4.0 4.0.0 - 2.6.122 + 2.7.27 5.0.0 6.4.0 2.0.3 diff --git a/src/Caching/StackExchangeRedis/src/RedisCache.Log.cs b/src/Caching/StackExchangeRedis/src/RedisCache.Log.cs index c20e93f52cef..5569613a2eb7 100644 --- a/src/Caching/StackExchangeRedis/src/RedisCache.Log.cs +++ b/src/Caching/StackExchangeRedis/src/RedisCache.Log.cs @@ -12,5 +12,8 @@ private static partial class Log { [LoggerMessage(1, LogLevel.Warning, "Could not determine the Redis server version. Falling back to use HMSET command instead of HSET.", EventName = "CouldNotDetermineServerVersion")] public static partial void CouldNotDetermineServerVersion(ILogger logger, Exception exception); + + [LoggerMessage(2, LogLevel.Debug, "Unable to add library name suffix.", EventName = "UnableToAddLibraryNameSuffix")] + internal static partial void UnableToAddLibraryNameSuffix(ILogger logger, Exception exception); } } diff --git a/src/Caching/StackExchangeRedis/src/RedisCache.cs b/src/Caching/StackExchangeRedis/src/RedisCache.cs index 9a896e0e5a7c..b346bbd24b4d 100644 --- a/src/Caching/StackExchangeRedis/src/RedisCache.cs +++ b/src/Caching/StackExchangeRedis/src/RedisCache.cs @@ -257,14 +257,7 @@ private IDatabase Connect() IConnectionMultiplexer connection; if (_options.ConnectionMultiplexerFactory is null) { - if (_options.ConfigurationOptions is not null) - { - connection = ConnectionMultiplexer.Connect(_options.ConfigurationOptions); - } - else - { - connection = ConnectionMultiplexer.Connect(_options.Configuration!); - } + connection = ConnectionMultiplexer.Connect(_options.GetConfiguredOptions()); } else { @@ -308,7 +301,7 @@ private async ValueTask ConnectSlowAsync(CancellationToken token) IConnectionMultiplexer connection; if (_options.ConnectionMultiplexerFactory is null) { - connection = await ConnectionMultiplexer.ConnectAsync(_options.GetConfiguredOptions("asp.net DC")).ConfigureAwait(false); + connection = await ConnectionMultiplexer.ConnectAsync(_options.GetConfiguredOptions()).ConfigureAwait(false); } else { @@ -332,6 +325,7 @@ private void PrepareConnection(IConnectionMultiplexer connection) WriteTimeTicks(ref _lastConnectTicks, DateTimeOffset.UtcNow); ValidateServerFeatures(connection); TryRegisterProfiler(connection); + TryAddSuffix(connection); } private void ValidateServerFeatures(IConnectionMultiplexer connection) @@ -369,6 +363,19 @@ private void TryRegisterProfiler(IConnectionMultiplexer connection) } } + private void TryAddSuffix(IConnectionMultiplexer connection) + { + try + { + connection.AddLibraryNameSuffix("aspnet"); + connection.AddLibraryNameSuffix("DC"); + } + catch (Exception ex) + { + Log.UnableToAddLibraryNameSuffix(_logger, ex); + } + } + private byte[]? GetAndRefresh(string key, bool getData) { ArgumentNullThrowHelper.ThrowIfNull(key); diff --git a/src/Caching/StackExchangeRedis/src/RedisCacheOptions.cs b/src/Caching/StackExchangeRedis/src/RedisCacheOptions.cs index f6386dc7b00a..23aad4f9e642 100644 --- a/src/Caching/StackExchangeRedis/src/RedisCacheOptions.cs +++ b/src/Caching/StackExchangeRedis/src/RedisCacheOptions.cs @@ -59,18 +59,13 @@ static bool GetDefaultValue() => set => _useForceReconnect = value; } - internal ConfigurationOptions GetConfiguredOptions(string libSuffix) + internal ConfigurationOptions GetConfiguredOptions() { - var options = ConfigurationOptions?.Clone() ?? ConfigurationOptions.Parse(Configuration!); + var options = ConfigurationOptions ?? ConfigurationOptions.Parse(Configuration!); // we don't want an initially unavailable server to prevent DI creating the service itself options.AbortOnConnectFail = false; - if (!string.IsNullOrWhiteSpace(libSuffix)) - { - var provider = DefaultOptionsProvider.GetProvider(options.EndPoints); - options.LibraryName = $"{provider.LibraryName} {libSuffix}"; - } return options; } } diff --git a/src/Middleware/Microsoft.AspNetCore.OutputCaching.StackExchangeRedis/src/RedisOutputCacheOptions.cs b/src/Middleware/Microsoft.AspNetCore.OutputCaching.StackExchangeRedis/src/RedisOutputCacheOptions.cs index a13262e03c28..ec42d5a5e16c 100644 --- a/src/Middleware/Microsoft.AspNetCore.OutputCaching.StackExchangeRedis/src/RedisOutputCacheOptions.cs +++ b/src/Middleware/Microsoft.AspNetCore.OutputCaching.StackExchangeRedis/src/RedisOutputCacheOptions.cs @@ -54,18 +54,13 @@ static bool GetDefaultValue() => set => _useForceReconnect = value; } - internal ConfigurationOptions GetConfiguredOptions(string libSuffix) + internal ConfigurationOptions GetConfiguredOptions() { - var options = ConfigurationOptions?.Clone() ?? ConfigurationOptions.Parse(Configuration!); + var options = ConfigurationOptions ?? ConfigurationOptions.Parse(Configuration!); // we don't want an initially unavailable server to prevent DI creating the service itself options.AbortOnConnectFail = false; - if (!string.IsNullOrWhiteSpace(libSuffix)) - { - var provider = DefaultOptionsProvider.GetProvider(options.EndPoints); - options.LibraryName = $"{provider.LibraryName} {libSuffix}"; - } return options; } } diff --git a/src/Middleware/Microsoft.AspNetCore.OutputCaching.StackExchangeRedis/src/RedisOutputCacheStore.Log.cs b/src/Middleware/Microsoft.AspNetCore.OutputCaching.StackExchangeRedis/src/RedisOutputCacheStore.Log.cs index adc254675c10..c80167695ebf 100644 --- a/src/Middleware/Microsoft.AspNetCore.OutputCaching.StackExchangeRedis/src/RedisOutputCacheStore.Log.cs +++ b/src/Middleware/Microsoft.AspNetCore.OutputCaching.StackExchangeRedis/src/RedisOutputCacheStore.Log.cs @@ -14,4 +14,7 @@ internal partial class RedisOutputCacheStore [LoggerMessage(2, LogLevel.Error, "Fatal error occurred executing redis output-cache GC loop.", EventName = "RedisOutputCacheGCFatalError")] internal static partial void RedisOutputCacheGCFatalError(ILogger logger, Exception exception); + + [LoggerMessage(3, LogLevel.Debug, "Unable to add library name suffix.", EventName = "UnableToAddLibraryNameSuffix")] + internal static partial void UnableToAddLibraryNameSuffix(ILogger logger, Exception exception); } diff --git a/src/Middleware/Microsoft.AspNetCore.OutputCaching.StackExchangeRedis/src/RedisOutputCacheStore.cs b/src/Middleware/Microsoft.AspNetCore.OutputCaching.StackExchangeRedis/src/RedisOutputCacheStore.cs index 3b8f1d21670b..1dc30df00f2c 100644 --- a/src/Middleware/Microsoft.AspNetCore.OutputCaching.StackExchangeRedis/src/RedisOutputCacheStore.cs +++ b/src/Middleware/Microsoft.AspNetCore.OutputCaching.StackExchangeRedis/src/RedisOutputCacheStore.cs @@ -332,7 +332,7 @@ private async ValueTask ConnectSlowAsync(CancellationToken token) IConnectionMultiplexer connection; if (_options.ConnectionMultiplexerFactory is null) { - connection = await ConnectionMultiplexer.ConnectAsync(_options.GetConfiguredOptions("asp.net OC")).ConfigureAwait(false); + connection = await ConnectionMultiplexer.ConnectAsync(_options.GetConfiguredOptions()).ConfigureAwait(false); } else { @@ -415,6 +415,7 @@ private void PrepareConnection(IConnectionMultiplexer connection) WriteTimeTicks(ref _lastConnectTicks, DateTimeOffset.UtcNow); ValidateServerFeatures(connection); TryRegisterProfiler(connection); + TryAddSuffix(connection); } private void ValidateServerFeatures(IConnectionMultiplexer connection) @@ -451,6 +452,19 @@ private void TryRegisterProfiler(IConnectionMultiplexer connection) } } + private void TryAddSuffix(IConnectionMultiplexer connection) + { + try + { + connection.AddLibraryNameSuffix("aspnet"); + connection.AddLibraryNameSuffix("OC"); + } + catch (Exception ex) + { + UnableToAddLibraryNameSuffix(_logger, ex); + } + } + private static void WriteTimeTicks(ref long field, DateTimeOffset value) { var ticks = value == DateTimeOffset.MinValue ? 0L : value.UtcTicks; diff --git a/src/Middleware/Microsoft.AspNetCore.OutputCaching.StackExchangeRedis/test/RedisConnectionFixture.cs b/src/Middleware/Microsoft.AspNetCore.OutputCaching.StackExchangeRedis/test/RedisConnectionFixture.cs index 23f379825dce..d7ea5529b41c 100644 --- a/src/Middleware/Microsoft.AspNetCore.OutputCaching.StackExchangeRedis/test/RedisConnectionFixture.cs +++ b/src/Middleware/Microsoft.AspNetCore.OutputCaching.StackExchangeRedis/test/RedisConnectionFixture.cs @@ -13,8 +13,9 @@ public RedisConnectionFixture() var options = new RedisOutputCacheOptions { Configuration = "127.0.0.1:6379", // TODO: CI test config here - }.GetConfiguredOptions("CI test"); + }.GetConfiguredOptions(); _muxer = ConnectionMultiplexer.Connect(options); + _muxer.AddLibraryNameSuffix("test"); } public IDatabase Database => _muxer.GetDatabase(); diff --git a/src/SignalR/server/StackExchangeRedis/src/RedisHubLifetimeManager.cs b/src/SignalR/server/StackExchangeRedis/src/RedisHubLifetimeManager.cs index acd18262d16e..f1743fa5f2d6 100644 --- a/src/SignalR/server/StackExchangeRedis/src/RedisHubLifetimeManager.cs +++ b/src/SignalR/server/StackExchangeRedis/src/RedisHubLifetimeManager.cs @@ -13,6 +13,7 @@ using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using StackExchange.Redis; +using RedisProtocol = Microsoft.AspNetCore.SignalR.StackExchangeRedis.Internal.RedisProtocol; // to disambiguate from StackExchange.Redis.RedisProtocol namespace Microsoft.AspNetCore.SignalR.StackExchangeRedis; diff --git a/src/SignalR/server/StackExchangeRedis/test/TestConnectionMultiplexer.cs b/src/SignalR/server/StackExchangeRedis/test/TestConnectionMultiplexer.cs index 953d1d46a83e..1768a7f97471 100644 --- a/src/SignalR/server/StackExchangeRedis/test/TestConnectionMultiplexer.cs +++ b/src/SignalR/server/StackExchangeRedis/test/TestConnectionMultiplexer.cs @@ -1,19 +1,12 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -using System; using System.Collections.Concurrent; -using System.Collections.Generic; -using System.Diagnostics; -using System.IO; using System.Net; using System.Reflection; -using System.Threading; -using System.Threading.Tasks; using StackExchange.Redis; using StackExchange.Redis.Maintenance; using StackExchange.Redis.Profiling; -using Xunit; namespace Microsoft.AspNetCore.SignalR.Tests; @@ -237,6 +230,8 @@ public IServer[] GetServers() } public ValueTask DisposeAsync() => default; + + public void AddLibraryNameSuffix(string suffix) { } // don't need to implement } public class TestRedisServer