From 264e54896d3ca1ab30d587110035c784a14e373b Mon Sep 17 00:00:00 2001 From: Dong Zhang <41927498+dzhangalibaba@users.noreply.github.com> Date: Mon, 5 Aug 2019 15:10:07 -0700 Subject: [PATCH] [orchagent]: Avoid crash by setting g_syncMode flag before create_switch (#1014) --- orchagent/main.cpp | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/orchagent/main.cpp b/orchagent/main.cpp index 34cd7c17c18e..a0bb8af5245a 100644 --- a/orchagent/main.cpp +++ b/orchagent/main.cpp @@ -220,14 +220,9 @@ int main(int argc, char **argv) attrs.push_back(attr); } - status = sai_switch_api->create_switch(&gSwitchId, (uint32_t)attrs.size(), attrs.data()); - if (status != SAI_STATUS_SUCCESS) - { - SWSS_LOG_ERROR("Failed to create a switch, rv:%d", status); - exit(EXIT_FAILURE); - } - SWSS_LOG_NOTICE("Create a switch"); - + // SAI_REDIS_SWITCH_ATTR_SYNC_MODE attribute only setBuffer and g_syncMode to true + // since it is not using ASIC_DB, we can execute it before create_switch + // when g_syncMode is set to true here, create_switch will wait the response from syncd if (gSyncMode) { attr.id = SAI_REDIS_SWITCH_ATTR_SYNC_MODE; @@ -236,6 +231,15 @@ int main(int argc, char **argv) sai_switch_api->set_switch_attribute(gSwitchId, &attr); } + + status = sai_switch_api->create_switch(&gSwitchId, (uint32_t)attrs.size(), attrs.data()); + if (status != SAI_STATUS_SUCCESS) + { + SWSS_LOG_ERROR("Failed to create a switch, rv:%d", status); + exit(EXIT_FAILURE); + } + SWSS_LOG_NOTICE("Create a switch"); + /* Get switch source MAC address if not provided */ if (!gMacAddress) {