Skip to content
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

Changed dot-netty.tcp.reuse-addr to default to 'off-for-windows' #3674

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4758,6 +4758,7 @@ namespace Akka.Util
public class static RuntimeDetector
{
public static readonly bool IsMono;
public static readonly bool IsWindows;
}
public class static StandardOutWriter
{
Expand Down
2 changes: 1 addition & 1 deletion src/core/Akka.Remote.Tests/RemoteConfigSpec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public void Remoting_should_contain_correct_heliosTCP_values_in_ReferenceConf()
Assert.Equal(4096, s.Backlog);
Assert.True(s.TcpNoDelay);
Assert.True(s.TcpKeepAlive);
Assert.True(s.TcpReuseAddr);
Assert.Equal("off-for-windows", c.GetString("tcp-reuse-addr"));
Assert.True(string.IsNullOrEmpty(c.GetString("hostname")));
Assert.Null(s.PublicPort);
Assert.Equal(2, s.ServerSocketWorkerPoolSize);
Expand Down
4 changes: 2 additions & 2 deletions src/core/Akka.Remote/Configuration/Remote.conf
Original file line number Diff line number Diff line change
Expand Up @@ -473,10 +473,10 @@ akka {

# Enables SO_REUSEADDR, which determines when an ActorSystem can open
# the specified listen port (the meaning differs between *nix and Windows)
# Valid values are "on", "off" and "off-for-windows"
# Valid values are "on", "off", and "off-for-windows"
# due to the following Windows bug: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4476378
# "off-for-windows" of course means that it's "on" for all other platforms
tcp-reuse-addr = on
tcp-reuse-addr = off-for-windows

# Used to configure the number of I/O worker threads on server sockets
server-socket-worker-pool {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,27 @@ public static DotNettyTransportSettings Create(ActorSystem system)
return Create(system.Settings.Config.GetConfig("akka.remote.dot-netty.tcp"));
}

/// <summary>
/// Adds support for the "off-for-windows" option per https://github.com/akkadotnet/akka.net/issues/3293
/// </summary>
/// <param name="hoconTcpReuseAddr">The HOCON string for the akka.remote.dot-netty.tcp.reuse-addr option</param>
/// <returns><c>true</c> if we should enable REUSE_ADDR for tcp. <c>false</c> otherwise.</returns>
internal static bool ResolveTcpReuseAddrOption(string hoconTcpReuseAddr)
{
switch (hoconTcpReuseAddr.ToLowerInvariant())
{
case "off-for-windows" when RuntimeDetector.IsWindows:
return false;
case "off-for-windows":
return true;
case "on":
return true;
case "off":
default:
return false;
}
}

public static DotNettyTransportSettings Create(Config config)
{
if (config == null) throw new ArgumentNullException(nameof(config), "DotNetty HOCON config was not found (default path: `akka.remote.dot-netty`)");
Expand Down Expand Up @@ -61,7 +82,7 @@ public static DotNettyTransportSettings Create(Config config)
maxFrameSize: ToNullableInt(config.GetByteSize("maximum-frame-size")) ?? 128000,
ssl: config.HasPath("ssl") ? SslSettings.Create(config.GetConfig("ssl")) : SslSettings.Empty,
dnsUseIpv6: config.GetBoolean("dns-use-ipv6", false),
tcpReuseAddr: config.GetBoolean("tcp-reuse-addr", true),
tcpReuseAddr: ResolveTcpReuseAddrOption(config.GetString("tcp-reuse-addr", "off-for-windows")),
tcpKeepAlive: config.GetBoolean("tcp-keepalive", true),
tcpNoDelay: config.GetBoolean("tcp-nodelay", true),
backlog: config.GetInt("backlog", 4096),
Expand Down
24 changes: 20 additions & 4 deletions src/core/Akka/Util/RuntimeDetector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@
//-----------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.InteropServices;

namespace Akka.Util
{
Expand All @@ -28,6 +25,25 @@ public static class RuntimeDetector
/// Is <c>true</c> if we're running on a Mono VM. <c>false</c> otherwise.
/// </summary>
public static readonly bool IsMono = Type.GetType("Mono.Runtime") != null;

/// <summary>
/// Is <c>true</c> if we've detected Windows as a platform.
/// </summary>
public static readonly bool IsWindows = _IsWindows();

/// <summary>
/// Private implementation method not meant for public consumption
/// </summary>
/// <returns><c>true</c> if the current runtime is Windows</returns>
private static bool _IsWindows()
{
#if CORECLR
return System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
#else
return System.Environment.OSVersion.Platform != PlatformID.MacOSX &&
System.Environment.OSVersion.Platform != PlatformID.Unix;
#endif
}
}
}