From 20fe6f4c4deb5f0c2b48128ee98846b2853633ea Mon Sep 17 00:00:00 2001 From: "Claudio D. Gasparini" Date: Fri, 5 Feb 2016 10:20:36 +0100 Subject: [PATCH] BUG-5243: Failed to send message Notify Don't try to send Notify message if the session has been closed externally Change-Id: Idd57bd5bf60e4f758ed0187bd12149854740cd36 Signed-off-by: Claudio D. Gasparini (cherry picked from commit 14cad280a7d1ba51f72d683e689eb3b2eca96909) --- .../protocol/bgp/rib/impl/BGPPeer.java | 6 +++++- .../protocol/bgp/rib/impl/BGPSessionImpl.java | 17 ++++++++--------- .../bgp/rib/impl/BGPSessionImplTest.java | 1 + 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/BGPPeer.java b/bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/BGPPeer.java index b33657c234..57d2d38ca9 100644 --- a/bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/BGPPeer.java +++ b/bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/BGPPeer.java @@ -248,7 +248,11 @@ public class BGPPeer implements BGPSessionListener, Peer, AutoCloseable, BGPPeer @Override public void onSessionDown(final BGPSession session, final Exception e) { - LOG.info("Session with peer {} went down", this.name, e); + if(e.getMessage().equals(BGPSessionImpl.END_OF_INPUT)) { + LOG.info("Session with peer {} went down", this.name); + } else { + LOG.info("Session with peer {} went down", this.name, e); + } releaseConnection(); } diff --git a/bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/BGPSessionImpl.java b/bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/BGPSessionImpl.java index dc5aa448e2..cfc01e536d 100644 --- a/bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/BGPSessionImpl.java +++ b/bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/BGPSessionImpl.java @@ -61,6 +61,8 @@ public class BGPSessionImpl extends SimpleChannelInboundHandler im private static final int KA_TO_DEADTIMER_RATIO = 3; + static final String END_OF_INPUT = "End of input detected. Close the session."; + /** * Internal session state. */ @@ -175,15 +177,11 @@ public class BGPSessionImpl extends SimpleChannelInboundHandler im @Override public synchronized void close() { - LOG.info("Closing session: {}", this); - - if (this.state != State.IDLE) { + if (this.state != State.IDLE && this.channel.isActive()) { this.writeAndFlush(new NotifyBuilder().setErrorCode(BGPError.CEASE.getCode()).setErrorSubcode( - BGPError.CEASE.getSubcode()).build()); - removePeerSession(); - this.channel.close(); - this.state = State.IDLE; + BGPError.CEASE.getSubcode()).build()); } + this.closeWithoutMessage(); } /** @@ -225,7 +223,8 @@ public class BGPSessionImpl extends SimpleChannelInboundHandler im public synchronized void endOfInput() { if (this.state == State.UP) { - this.listener.onSessionDown(this, new IOException("End of input detected. Close the session.")); + LOG.info(END_OF_INPUT); + this.listener.onSessionDown(this, new IOException(END_OF_INPUT)); } } @@ -268,7 +267,7 @@ public class BGPSessionImpl extends SimpleChannelInboundHandler im } private synchronized void closeWithoutMessage() { - LOG.debug("Closing session: {}", this); + LOG.info("Closing session: {}", this); removePeerSession(); this.channel.close(); this.state = State.IDLE; diff --git a/bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/BGPSessionImplTest.java b/bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/BGPSessionImplTest.java index e9352b2d2c..06fdec8914 100644 --- a/bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/BGPSessionImplTest.java +++ b/bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/BGPSessionImplTest.java @@ -120,6 +120,7 @@ public class BGPSessionImplTest { } }).when(this.speakerListener).writeAndFlush(any(Notification.class)); doReturn(this.eventLoop).when(this.speakerListener).eventLoop(); + doReturn(true).when(this.speakerListener).isActive(); doAnswer(new Answer() { @Override public Void answer(final InvocationOnMock invocation) throws Throwable { -- 2.36.6