From: Ajay Date: Mon, 29 Aug 2016 20:56:34 +0000 (+0000) Subject: Bug-6468: Duplicate cleanup and connected-peer-counter decrement during BGP session... X-Git-Tag: release/carbon~173 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=78b58179e6ef65fae98b134112e7aa0bbe7e1a91;p=bgpcep.git Bug-6468: Duplicate cleanup and connected-peer-counter decrement during BGP session cleanup 1. Add synchronized to BGPPeer#releaseConnection to avoid race condition 2. Add check to BGPSessionImpl#closeWithoutMessage so that it's body does not get executed twice, even if it does get called twice during session cleanup Change-Id: I78d89de2c9c0fa8968bbb6a019d568a539a8c5f7 Signed-off-by: Ajay --- 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 ad269b6dea..272ce08200 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 @@ -338,7 +338,7 @@ public class BGPPeer implements BGPSessionListener, Peer, AutoCloseable, BGPPeer } } - private synchronized void cleanup() { + private void cleanup() { // FIXME: BUG-196: support graceful this.adjRibOutListenerSet.values().forEach(AdjRibOutListener::close); this.adjRibOutListenerSet.clear(); @@ -384,7 +384,8 @@ public class BGPPeer implements BGPSessionListener, Peer, AutoCloseable, BGPPeer } @Override - public void releaseConnection() { + @GuardedBy("this") + public synchronized void releaseConnection() { if (this.rpcRegistration != null) { this.rpcRegistration.close(); } @@ -399,7 +400,6 @@ public class BGPPeer implements BGPSessionListener, Peer, AutoCloseable, BGPPeer } } - @GuardedBy("this") private void dropConnection() { if (this.runtimeReg != null) { this.runtimeReg.close(); 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 fcb38fab03..9f3277539f 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 @@ -226,8 +226,8 @@ public class BGPSessionImpl extends SimpleChannelInboundHandler im public synchronized void close() { if (this.state != State.IDLE) { this.writeAndFlush(new NotifyBuilder().setErrorCode(BGPError.CEASE.getCode()).setErrorSubcode(BGPError.CEASE.getSubcode()).build()); + this.closeWithoutMessage(); } - this.closeWithoutMessage(); } /** @@ -314,6 +314,9 @@ public class BGPSessionImpl extends SimpleChannelInboundHandler im } private synchronized void closeWithoutMessage() { + if (this.state == State.IDLE) { + return; + } LOG.info("Closing session: {}", this); removePeerSession(); this.channel.close().addListener(new ChannelFutureListener() {