Skip to content

Commit 264e548

Browse files
dzhangalibabastcheng
authored andcommitted
[orchagent]: Avoid crash by setting g_syncMode flag before create_switch (sonic-net#1014)
1 parent 34b582c commit 264e548

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

orchagent/main.cpp

+12-8
Original file line numberDiff line numberDiff line change
@@ -220,14 +220,9 @@ int main(int argc, char **argv)
220220
attrs.push_back(attr);
221221
}
222222

223-
status = sai_switch_api->create_switch(&gSwitchId, (uint32_t)attrs.size(), attrs.data());
224-
if (status != SAI_STATUS_SUCCESS)
225-
{
226-
SWSS_LOG_ERROR("Failed to create a switch, rv:%d", status);
227-
exit(EXIT_FAILURE);
228-
}
229-
SWSS_LOG_NOTICE("Create a switch");
230-
223+
// SAI_REDIS_SWITCH_ATTR_SYNC_MODE attribute only setBuffer and g_syncMode to true
224+
// since it is not using ASIC_DB, we can execute it before create_switch
225+
// when g_syncMode is set to true here, create_switch will wait the response from syncd
231226
if (gSyncMode)
232227
{
233228
attr.id = SAI_REDIS_SWITCH_ATTR_SYNC_MODE;
@@ -236,6 +231,15 @@ int main(int argc, char **argv)
236231
sai_switch_api->set_switch_attribute(gSwitchId, &attr);
237232
}
238233

234+
235+
status = sai_switch_api->create_switch(&gSwitchId, (uint32_t)attrs.size(), attrs.data());
236+
if (status != SAI_STATUS_SUCCESS)
237+
{
238+
SWSS_LOG_ERROR("Failed to create a switch, rv:%d", status);
239+
exit(EXIT_FAILURE);
240+
}
241+
SWSS_LOG_NOTICE("Create a switch");
242+
239243
/* Get switch source MAC address if not provided */
240244
if (!gMacAddress)
241245
{

0 commit comments

Comments
 (0)