Bug-6468: Duplicate cleanup and connected-peer-counter decrement during BGP session... 11/44811/2
authorAjay <ajayl.bro@gmail.com>
Mon, 29 Aug 2016 20:56:34 +0000 (20:56 +0000)
committerMilos Fabian <milfabia@cisco.com>
Wed, 31 Aug 2016 14:20:46 +0000 (14:20 +0000)
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 <ajayl.bro@gmail.com>
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/BGPPeer.java
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/BGPSessionImpl.java

index ad269b6dea7708c8d28a3dc5718460aaae4ff251..272ce08200bbdf94d7c525e75c1066390c28610d 100644 (file)
@@ -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();
index fcb38fab03e94bd996d70870fd7d72cc8420c929..9f3277539ff7cc4de86829a1e46f1b2daafaa3cd 100644 (file)
@@ -226,8 +226,8 @@ public class BGPSessionImpl extends SimpleChannelInboundHandler<Notification> 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<Notification> im
     }
 
     private synchronized void closeWithoutMessage() {
+        if (this.state == State.IDLE) {
+            return;
+        }
         LOG.info("Closing session: {}", this);
         removePeerSession();
         this.channel.close().addListener(new ChannelFutureListener() {