diff --git a/akka-actor/src/main/scala/akka/io/SelectionHandler.scala b/akka-actor/src/main/scala/akka/io/SelectionHandler.scala index 74fee61b83..41c58a39b6 100644 --- a/akka-actor/src/main/scala/akka/io/SelectionHandler.scala +++ b/akka-actor/src/main/scala/akka/io/SelectionHandler.scala @@ -20,6 +20,7 @@ import akka.util.SerializedSuspendableExecutionContext import akka.actor._ import akka.routing.RandomPool import akka.event.Logging +import java.nio.channels.ClosedChannelException abstract class SelectionHandlerSettings(config: Config) { import config._ @@ -153,12 +154,15 @@ private[io] object SelectionHandler { def register(channel: SelectableChannel, initialOps: Int)(implicit channelActor: ActorRef): Unit = execute { new Task { - def tryRun(): Unit = { + def tryRun(): Unit = try { val key = channel.register(selector, initialOps, channelActor) channelActor ! new ChannelRegistration { def enableInterest(ops: Int): Unit = enableInterestOps(key, ops) def disableInterest(ops: Int): Unit = disableInterestOps(key, ops) } + } catch { + case _: ClosedChannelException ⇒ + // ignore, might happen if a connection is closed in the same moment as an interest is registered } } }