diff --git a/Jellyfin.Networking/HappyEyeballs/HttpClientExtension.cs b/Jellyfin.Networking/HappyEyeballs/HttpClientExtension.cs index 12b42cc6e1..6760869107 100644 --- a/Jellyfin.Networking/HappyEyeballs/HttpClientExtension.cs +++ b/Jellyfin.Networking/HappyEyeballs/HttpClientExtension.cs @@ -35,6 +35,11 @@ namespace Jellyfin.Networking.HappyEyeballs { private const int ConnectionEstablishTimeout = 2000; + /// + /// Interlocked doesn't support bool types. + /// + private static int _useIPv6 = 0; + /// /// Gets a value indicating whether the initial IPv6 check has been performed (to determine whether v6 is available or not). /// @@ -43,7 +48,21 @@ namespace Jellyfin.Networking.HappyEyeballs /// /// Gets or sets a value indicating whether IPv6 should be preferred. Value may change based on runtime failures. /// - public static bool? UseIPv6 { get; set; } = null; + public static bool UseIPv6 + { + get => Interlocked.CompareExchange(ref _useIPv6, 1, 1) == 1; + set + { + if (value) + { + Interlocked.CompareExchange(ref _useIPv6, 1, 0); + } + else + { + Interlocked.CompareExchange(ref _useIPv6, 0, 1); + } + } + } /// /// Implements the httpclient callback method. @@ -56,7 +75,7 @@ namespace Jellyfin.Networking.HappyEyeballs // Until .NET supports an implementation of Happy Eyeballs (https://tools.ietf.org/html/rfc8305#section-2), // let's make IPv4 fallback work in a simple way. This issue is being tracked at https://github.com/dotnet/runtime/issues/26177 // and expected to be fixed in .NET 6. - if (UseIPv6 == true) + if (UseIPv6) { try {