Skip to content

Commit 7382995

Browse files
authored
[routeorch]: Fix observer detaching procedure for next hop observers (sonic-net#985)
- erase the correct observer in the observer list - remove the NextHopObserverEntry once no observer is observing the entry - refine some logs and comments Signed-off-by: Shu0T1an ChenG <[email protected]>
1 parent 63afbd5 commit 7382995

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

orchagent/routeorch.cpp

+19-3
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ void RouteOrch::attach(Observer *observer, const IpAddress& dstAddr)
160160
dstAddr.to_string().c_str());
161161

162162
// Trigger next hop change for the first time the observer is attached
163+
// Note that rbegin() is pointing to the entry with longest prefix match
163164
auto route = observerEntry->second.routeTable.rbegin();
164165
if (route != observerEntry->second.routeTable.rend())
165166
{
@@ -171,19 +172,34 @@ void RouteOrch::attach(Observer *observer, const IpAddress& dstAddr)
171172
void RouteOrch::detach(Observer *observer, const IpAddress& dstAddr)
172173
{
173174
SWSS_LOG_ENTER();
175+
174176
auto observerEntry = m_nextHopObservers.find(dstAddr);
175177

176178
if (observerEntry == m_nextHopObservers.end())
177179
{
178-
SWSS_LOG_ERROR("Failed to detach observer for %s. Entry not found.\n", dstAddr.to_string().c_str());
180+
SWSS_LOG_ERROR("Failed to locate observer for destination IP %s",
181+
dstAddr.to_string().c_str());
179182
assert(false);
183+
return;
180184
}
181185

182-
for (auto iter = observerEntry->second.observers.begin(); iter != observerEntry->second.observers.end(); ++iter)
186+
// Find the observer
187+
for (auto iter = observerEntry->second.observers.begin();
188+
iter != observerEntry->second.observers.end(); ++iter)
183189
{
184190
if (observer == *iter)
185191
{
186-
m_observers.erase(iter);
192+
observerEntry->second.observers.erase(iter);
193+
194+
SWSS_LOG_NOTICE("Detached next hop observer for destination IP %s",
195+
dstAddr.to_string().c_str());
196+
197+
// Remove NextHopObserverEntry if no observer is tracking this
198+
// destination IP.
199+
if (observerEntry->second.observers.empty())
200+
{
201+
m_nextHopObservers.erase(observerEntry);
202+
}
187203
break;
188204
}
189205
}

0 commit comments

Comments
 (0)