Ignore incoming messages in State.FAILED
[netconf.git] / netconf / netconf-netty-util / src / main / java / org / opendaylight / netconf / nettyutil / AbstractNetconfSessionNegotiator.java
index c72312fa79558d16110085f7e438aece60a46885..ef71afc3cdf8ee07570778223627f780d5620197 100644 (file)
@@ -134,9 +134,13 @@ public abstract class AbstractNetconfSessionNegotiator<S extends AbstractNetconf
         }
     }
 
-    protected final synchronized boolean ifNegotiatedAlready() {
+    protected final boolean ifNegotiatedAlready() {
         // Indicates whether negotiation already started
-        return this.state != State.IDLE;
+        return state() != State.IDLE;
+    }
+
+    private synchronized State state() {
+        return state;
     }
 
     private static @Nullable SslHandler getSslHandler(final Channel channel) {
@@ -373,6 +377,11 @@ public abstract class AbstractNetconfSessionNegotiator<S extends AbstractNetconf
     @Override
     @SuppressWarnings("checkstyle:illegalCatch")
     public final void channelRead(final ChannelHandlerContext ctx, final Object msg) {
+        if (state() == State.FAILED) {
+            // We have already failed -- do not process any more messages
+            return;
+        }
+
         LOG.debug("Negotiation read invoked on channel {}", channel);
         try {
             handleMessage((NetconfHelloMessage) msg);