Guard against torn down peer 60/80760/2
authorRobert Varga <robert.varga@pantheon.tech>
Mon, 11 Mar 2019 10:04:32 +0000 (11:04 +0100)
committerRobert Varga <nite@hq.sk>
Mon, 11 Mar 2019 10:49:45 +0000 (10:49 +0000)
When we fail to look up peer we should not be throwing a NPE, as we
will end up with inconsistent TransactionChain.

Change-Id: Ia662d4fcb777cce5323fbad820466c9350ec039b
JIRA: BGPCEP-863
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/BGPRouteEntryExportParametersImpl.java
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/AbstractPeer.java

index 21ee2cd790fc3ed82706a7655c1f6575f4b941f0..a1c31992f0b2eb70da32061dea36d08fb501278f 100644 (file)
@@ -7,6 +7,8 @@
  */
 package org.opendaylight.protocol.bgp.mode.impl;
 
+import static java.util.Objects.requireNonNull;
+
 import java.util.List;
 import org.opendaylight.protocol.bgp.rib.spi.Peer;
 import org.opendaylight.protocol.bgp.rib.spi.policy.BGPRouteEntryExportParameters;
@@ -26,8 +28,8 @@ public final class BGPRouteEntryExportParametersImpl implements BGPRouteEntryExp
 
     public BGPRouteEntryExportParametersImpl(final Peer fromPeer, final Peer toPeer,
             final String routeKey, final RTCCache rtCache) {
-        this.fromPeer = fromPeer;
-        this.toPeer = toPeer;
+        this.fromPeer = requireNonNull(fromPeer);
+        this.toPeer = requireNonNull(toPeer);
         this.routeKey = routeKey;
         this.rtCache = rtCache;
     }
index 664eda9e459125757110c2591bf50ec9e8fb3267..204d41a74a023f0def989fefddb7459d83d5ea45 100644 (file)
@@ -250,6 +250,11 @@ abstract class AbstractPeer extends BGPPeerStateImpl implements BGPRouteEntryImp
 
             final R route = initializingRoute.getRoute();
             final Peer fromPeer = entryDep.getPeerTracker().getPeer(fromPeerId);
+            if (fromPeer == null) {
+                LOG.debug("Failed to acquire peer structure for {}, ignoring route {}", fromPeerId, initializingRoute);
+                continue;
+            }
+
             final BGPRouteEntryExportParameters routeEntry = new BGPRouteEntryExportParametersImpl(fromPeer,
                     this, route.getRouteKey(), this.rtCache);