Skip to content

Commit 2902ba0

Browse files
stepanblyschakstcheng
authored andcommitted
[portsyncd]: Fix portsyncd restart case (sonic-net#1019)
I noticed that after swss restart in VS orchagent does not receive PortInitDone. I looked at the comment about "g_portSet" says that: When this LinkSync class is * initialized, we check the database to see if some of the ports' host * interfaces are already created and remove them from this set. However g_portSet was filled after LinkSync is initialized, so I considered this is a bug causing orchagent does not receive PortInitDone when portsyncd starts after host interfaces were created. Signed-off-by: Stepan Blyschak <[email protected]>
1 parent fcddc0f commit 2902ba0

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

portsyncd/linksync.cpp

+9-2
Original file line numberDiff line numberDiff line change
@@ -95,20 +95,27 @@ LinkSync::LinkSync(DBConnector *appl_db, DBConnector *state_db) :
9595
if (!WarmStart::isWarmStart())
9696
{
9797
/* See the comments for g_portSet in portsyncd.cpp */
98-
for (string port : g_portSet)
98+
for (auto port_iter = g_portSet.begin(); port_iter != g_portSet.end();)
9999
{
100+
string port = *port_iter;
100101
vector<FieldValueTuple> temp;
102+
bool portFound = false;
101103
if (m_portTable.get(port, temp))
102104
{
103105
for (auto it : temp)
104106
{
105107
if (fvField(it) == "admin_status")
106108
{
107-
g_portSet.erase(port);
109+
port_iter = g_portSet.erase(port_iter);
110+
portFound = true;
108111
break;
109112
}
110113
}
111114
}
115+
if (!portFound)
116+
{
117+
++port_iter;
118+
}
112119
}
113120

114121
for (idx_p = if_ni;

portsyncd/portsyncd.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,6 @@ int main(int argc, char **argv)
7979
WarmStart::checkWarmStart("portsyncd", "swss");
8080
const bool warm = WarmStart::isWarmStart();
8181

82-
LinkSync sync(&appl_db, &state_db);
83-
NetDispatcher::getInstance().registerMessageHandler(RTM_NEWLINK, &sync);
84-
NetDispatcher::getInstance().registerMessageHandler(RTM_DELLINK, &sync);
85-
8682
try
8783
{
8884
NetLink netlink;
@@ -102,6 +98,10 @@ int main(int argc, char **argv)
10298
}
10399
}
104100

101+
LinkSync sync(&appl_db, &state_db);
102+
NetDispatcher::getInstance().registerMessageHandler(RTM_NEWLINK, &sync);
103+
NetDispatcher::getInstance().registerMessageHandler(RTM_DELLINK, &sync);
104+
105105
s.addSelectable(&netlink);
106106
s.addSelectable(&portCfg);
107107

0 commit comments

Comments
 (0)