#2742 - making reuseAddress default false on windows with option to turn it on for everybody or off for everybody

This commit is contained in:
Viktor Klang 2012-12-17 20:44:59 +01:00
parent 68f72459a3
commit 3ff997a3ca
7 changed files with 24 additions and 4 deletions

View file

@ -24,6 +24,7 @@ import java.util.concurrent.ThreadFactory;
import java.util.concurrent.locks.ReadWriteLock; import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock; import java.util.concurrent.locks.ReentrantReadWriteLock;
import akka.util.Helpers;
import scala.concurrent.duration.Duration; import scala.concurrent.duration.Duration;
import scala.concurrent.duration.FiniteDuration; import scala.concurrent.duration.FiniteDuration;
import akka.event.LoggingAdapter; import akka.event.LoggingAdapter;
@ -91,7 +92,6 @@ public class HashedWheelTimer implements Timer {
final ReusableIterator<HashedWheelTimeout>[] iterators; final ReusableIterator<HashedWheelTimeout>[] iterators;
final int mask; final int mask;
final ReadWriteLock lock = new ReentrantReadWriteLock(); final ReadWriteLock lock = new ReentrantReadWriteLock();
final boolean isWindows = System.getProperty("os.name", "").toLowerCase().indexOf("win") >= 0;
volatile int wheelCursor; volatile int wheelCursor;
private LoggingAdapter logger; private LoggingAdapter logger;
@ -396,7 +396,7 @@ public class HashedWheelTimer implements Timer {
// the JVM if it runs on windows. // the JVM if it runs on windows.
// //
// See https://github.com/netty/netty/issues/356 // See https://github.com/netty/netty/issues/356
if (isWindows) { if (Helpers.isWindows()) {
sleepTimeMs = (sleepTimeMs / 10) * 10; sleepTimeMs = (sleepTimeMs / 10) * 10;
} }

View file

@ -9,6 +9,8 @@ import java.util.regex.Pattern
object Helpers { object Helpers {
val isWindows: Boolean = System.getProperty("os.name", "").toLowerCase.indexOf("win") >= 0
def makePattern(s: String): Pattern = Pattern.compile("^\\Q" + s.replace("?", "\\E.\\Q").replace("*", "\\E.*\\Q") + "\\E$") def makePattern(s: String): Pattern = Pattern.compile("^\\Q" + s.replace("?", "\\E.\\Q").replace("*", "\\E.*\\Q") + "\\E$")
def compareIdentityHash(a: AnyRef, b: AnyRef): Int = { def compareIdentityHash(a: AnyRef, b: AnyRef): Int = {

View file

@ -13,6 +13,7 @@ import org.jboss.netty.handler.timeout.{ ReadTimeoutHandler, ReadTimeoutExceptio
import java.net.InetSocketAddress import java.net.InetSocketAddress
import java.util.concurrent.Executors import java.util.concurrent.Executors
import akka.event.Logging import akka.event.Logging
import akka.util.Helpers
/** /**
* INTERNAL API. * INTERNAL API.
@ -59,7 +60,7 @@ private[akka] object RemoteConnection {
poolSize) poolSize)
val bootstrap = new ServerBootstrap(socketfactory) val bootstrap = new ServerBootstrap(socketfactory)
bootstrap.setPipelineFactory(new TestConductorPipelineFactory(handler)) bootstrap.setPipelineFactory(new TestConductorPipelineFactory(handler))
bootstrap.setOption("reuseAddress", true) bootstrap.setOption("reuseAddress", !Helpers.isWindows)
bootstrap.setOption("child.tcpNoDelay", true) bootstrap.setOption("child.tcpNoDelay", true)
bootstrap.bind(sockaddr) bootstrap.bind(sockaddr)
} }

View file

@ -141,6 +141,11 @@ akka {
# (I) Sets the size of the connection backlog # (I) Sets the size of the connection backlog
backlog = 4096 backlog = 4096
# (I) Sets the SO_REUSE_ADDR flag, 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
reuse-address = off-for-windows
# (I) Length in akka.time-unit how long core threads will be kept alive if # (I) Length in akka.time-unit how long core threads will be kept alive if
# idling # idling
execution-pool-keepalive = 60s execution-pool-keepalive = 60s

View file

@ -37,7 +37,7 @@ private[akka] class NettyRemoteServer(val netty: NettyRemoteTransport) {
b.setOption("backlog", settings.Backlog) b.setOption("backlog", settings.Backlog)
b.setOption("tcpNoDelay", true) b.setOption("tcpNoDelay", true)
b.setOption("child.keepAlive", true) b.setOption("child.keepAlive", true)
b.setOption("reuseAddress", true) b.setOption("reuseAddress", settings.ReuseAddress)
settings.ReceiveBufferSize.foreach(sz b.setOption("receiveBufferSize", sz)) settings.ReceiveBufferSize.foreach(sz b.setOption("receiveBufferSize", sz))
settings.SendBufferSize.foreach(sz b.setOption("sendBufferSize", sz)) settings.SendBufferSize.foreach(sz b.setOption("sendBufferSize", sz))
settings.WriteBufferHighWaterMark.foreach(sz b.setOption("writeBufferHighWaterMark", sz)) settings.WriteBufferHighWaterMark.foreach(sz b.setOption("writeBufferHighWaterMark", sz))

View file

@ -11,6 +11,7 @@ import akka.ConfigurationException
import akka.japi.Util.immutableSeq import akka.japi.Util.immutableSeq
import scala.concurrent.duration.FiniteDuration import scala.concurrent.duration.FiniteDuration
import akka.dispatch.ThreadPoolConfig import akka.dispatch.ThreadPoolConfig
import akka.util.Helpers
private[akka] class NettySettings(config: Config, val systemName: String) { private[akka] class NettySettings(config: Config, val systemName: String) {
@ -72,6 +73,11 @@ private[akka] class NettySettings(config: Config, val systemName: String) {
val Backlog: Int = getInt("backlog") val Backlog: Int = getInt("backlog")
val ReuseAddress: Boolean = getString("reuse-address") match {
case "off-for-windows" !Helpers.isWindows
case _ getBoolean("reuse-address")
}
val ExecutionPoolKeepalive: FiniteDuration = Duration(getMilliseconds("execution-pool-keepalive"), MILLISECONDS) val ExecutionPoolKeepalive: FiniteDuration = Duration(getMilliseconds("execution-pool-keepalive"), MILLISECONDS)
val ExecutionPoolSize: Int = getInt("execution-pool-size") match { val ExecutionPoolSize: Int = getInt("execution-pool-size") match {

View file

@ -9,6 +9,7 @@ import akka.testkit.AkkaSpec
import akka.actor.ExtendedActorSystem import akka.actor.ExtendedActorSystem
import scala.concurrent.duration._ import scala.concurrent.duration._
import akka.remote.netty.NettyRemoteTransport import akka.remote.netty.NettyRemoteTransport
import akka.util.Helpers
@org.junit.runner.RunWith(classOf[org.scalatest.junit.JUnitRunner]) @org.junit.runner.RunWith(classOf[org.scalatest.junit.JUnitRunner])
class RemoteConfigSpec extends AkkaSpec( class RemoteConfigSpec extends AkkaSpec(
@ -49,6 +50,7 @@ class RemoteConfigSpec extends AkkaSpec(
MessageFrameSize must be(1048576) MessageFrameSize must be(1048576)
ConnectionTimeout must be(2 minutes) ConnectionTimeout must be(2 minutes)
Backlog must be(4096) Backlog must be(4096)
ReuseAddress must be(!Helpers.isWindows)
ExecutionPoolKeepalive must be(1 minute) ExecutionPoolKeepalive must be(1 minute)
ExecutionPoolSize must be(4) ExecutionPoolSize must be(4)
MaxChannelMemorySize must be(0) MaxChannelMemorySize must be(0)
@ -88,6 +90,10 @@ class RemoteConfigSpec extends AkkaSpec(
pool.getDouble("pool-size-factor") must equal(1.0) pool.getDouble("pool-size-factor") must equal(1.0)
pool.getInt("pool-size-max") must equal(8) pool.getInt("pool-size-max") must equal(8)
} }
{
c.getString("reuse-address") must be("off-for-windows")
}
} }
} }
} }