diff --git a/syncd/syncd.cpp b/syncd/syncd.cpp index 5de74e8429da..869f9b1ec71b 100644 --- a/syncd/syncd.cpp +++ b/syncd/syncd.cpp @@ -3398,6 +3398,12 @@ int syncd_main(int argc, char **argv) SWSS_LOG_NOTICE("Removing the switch gSwitchId=0x%lx", gSwitchId); sai_switch_api_t *sai_switch_api = NULL; sai_api_query(SAI_API_SWITCH, (void**)&sai_switch_api); + + FlexCounter::removeAllCounters(); + + // Stop notification thread before removing switch + stopNotificationsProcessingThread(); + status = sai_switch_api->remove_switch(gSwitchId); if (status != SAI_STATUS_SUCCESS) { @@ -3413,8 +3419,6 @@ int syncd_main(int argc, char **argv) SWSS_LOG_ERROR("failed to uninitialize api: %s", sai_serialize_status(status).c_str()); } - stopNotificationsProcessingThread(); - SWSS_LOG_NOTICE("uninitialize finished"); return EXIT_SUCCESS; diff --git a/syncd/syncd_flex_counter.cpp b/syncd/syncd_flex_counter.cpp index 40e24bd1e6ca..71388046567a 100644 --- a/syncd/syncd_flex_counter.cpp +++ b/syncd/syncd_flex_counter.cpp @@ -331,6 +331,13 @@ void FlexCounter::removeCounterPlugin( } } +void FlexCounter::removeAllCounters() +{ + SWSS_LOG_ENTER(); + + g_flex_counters_map.clear(); +} + FlexCounter::~FlexCounter(void) { diff --git a/syncd/syncd_flex_counter.h b/syncd/syncd_flex_counter.h index 1771feb2ae38..111fc8260851 100644 --- a/syncd/syncd_flex_counter.h +++ b/syncd/syncd_flex_counter.h @@ -51,6 +51,7 @@ class FlexCounter _In_ std::string instanceId); static void removeCounterPlugin( _In_ std::string instanceId); + static void removeAllCounters(); FlexCounter( _In_ const FlexCounter&) = delete; diff --git a/syncd/syncd_notifications.cpp b/syncd/syncd_notifications.cpp index 7bc8ee16161f..e4958e819602 100644 --- a/syncd/syncd_notifications.cpp +++ b/syncd/syncd_notifications.cpp @@ -559,8 +559,6 @@ void startNotificationsProcessingThread() runThread = true; ntf_process_thread = std::make_shared(ntf_process_function); - - ntf_process_thread->detach(); } void stopNotificationsProcessingThread()