=act #3645 Make TcpOutgoingConnection actor handle UnresolvedAddressExceptions
This commit is contained in:
parent
e05d30aeaa
commit
bb1b22bffd
2 changed files with 27 additions and 10 deletions
|
|
@ -544,6 +544,16 @@ class TcpConnectionSpec extends AkkaSpec("""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
"report failed connection attempt when target cannot be resolved" in
|
||||||
|
new UnacceptedConnectionTest() {
|
||||||
|
val address = new InetSocketAddress("notthere.local", 666)
|
||||||
|
override lazy val connectionActor = createConnectionActorWithoutRegistration(serverAddress = address)
|
||||||
|
run {
|
||||||
|
connectionActor ! newChannelRegistration
|
||||||
|
userHandler.expectMsg(30.seconds, CommandFailed(Connect(address)))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
"report failed connection attempt when timing out" in
|
"report failed connection attempt when timing out" in
|
||||||
new UnacceptedConnectionTest() {
|
new UnacceptedConnectionTest() {
|
||||||
override lazy val connectionActor = createConnectionActor(serverAddress = UnboundAddress, timeout = Option(100.millis))
|
override lazy val connectionActor = createConnectionActor(serverAddress = UnboundAddress, timeout = Option(100.millis))
|
||||||
|
|
@ -758,16 +768,24 @@ class TcpConnectionSpec extends AkkaSpec("""
|
||||||
def createConnectionActor(serverAddress: InetSocketAddress = serverAddress,
|
def createConnectionActor(serverAddress: InetSocketAddress = serverAddress,
|
||||||
options: immutable.Seq[SocketOption] = Nil,
|
options: immutable.Seq[SocketOption] = Nil,
|
||||||
timeout: Option[FiniteDuration] = None): TestActorRef[TcpOutgoingConnection] = {
|
timeout: Option[FiniteDuration] = None): TestActorRef[TcpOutgoingConnection] = {
|
||||||
val ref = TestActorRef(
|
val ref = createConnectionActorWithoutRegistration(serverAddress, options, timeout)
|
||||||
new TcpOutgoingConnection(Tcp(system), this, userHandler.ref, Connect(serverAddress, options = options, timeout = timeout)) {
|
ref ! newChannelRegistration
|
||||||
override def postRestart(reason: Throwable): Unit = context.stop(self) // ensure we never restart
|
ref
|
||||||
})
|
}
|
||||||
ref ! new ChannelRegistration {
|
|
||||||
|
def newChannelRegistration: ChannelRegistration =
|
||||||
|
new ChannelRegistration {
|
||||||
def enableInterest(op: Int): Unit = interestCallReceiver.ref ! op
|
def enableInterest(op: Int): Unit = interestCallReceiver.ref ! op
|
||||||
def disableInterest(op: Int): Unit = interestCallReceiver.ref ! -op
|
def disableInterest(op: Int): Unit = interestCallReceiver.ref ! -op
|
||||||
}
|
}
|
||||||
ref
|
|
||||||
}
|
def createConnectionActorWithoutRegistration(serverAddress: InetSocketAddress = serverAddress,
|
||||||
|
options: immutable.Seq[SocketOption] = Nil,
|
||||||
|
timeout: Option[FiniteDuration] = None): TestActorRef[TcpOutgoingConnection] =
|
||||||
|
TestActorRef(
|
||||||
|
new TcpOutgoingConnection(Tcp(system), this, userHandler.ref, Connect(serverAddress, options = options, timeout = timeout)) {
|
||||||
|
override def postRestart(reason: Throwable): Unit = context.stop(self) // ensure we never restart
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
trait SmallRcvBuffer { _: LocalServerTest ⇒
|
trait SmallRcvBuffer { _: LocalServerTest ⇒
|
||||||
|
|
|
||||||
|
|
@ -4,9 +4,8 @@
|
||||||
|
|
||||||
package akka.io
|
package akka.io
|
||||||
|
|
||||||
import java.io.IOException
|
|
||||||
import java.nio.channels.{ SelectionKey, SocketChannel }
|
import java.nio.channels.{ SelectionKey, SocketChannel }
|
||||||
import java.net.ConnectException
|
import scala.util.control.NonFatal
|
||||||
import scala.collection.immutable
|
import scala.collection.immutable
|
||||||
import scala.concurrent.duration._
|
import scala.concurrent.duration._
|
||||||
import akka.actor.{ ReceiveTimeout, ActorRef }
|
import akka.actor.{ ReceiveTimeout, ActorRef }
|
||||||
|
|
@ -42,7 +41,7 @@ private[io] class TcpOutgoingConnection(_tcp: TcpExt,
|
||||||
try {
|
try {
|
||||||
thunk
|
thunk
|
||||||
} catch {
|
} catch {
|
||||||
case e: IOException ⇒
|
case NonFatal(e) ⇒
|
||||||
log.debug("Could not establish connection to [{}] due to {}", remoteAddress, e)
|
log.debug("Could not establish connection to [{}] due to {}", remoteAddress, e)
|
||||||
stop()
|
stop()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue