From db8f3f8e02c1a5658c05ac472e26cf271a9e1f2c Mon Sep 17 00:00:00 2001 From: Patrik Nordwall Date: Mon, 11 Apr 2016 18:03:58 +0200 Subject: [PATCH] ignore ClosedChannelException when register selector, #16035 --- akka-actor/src/main/scala/akka/io/SelectionHandler.scala | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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 } } }