From 67278beb7baa1b4cecd702b7da5ba69c1684505b Mon Sep 17 00:00:00 2001 From: Nazarii Hnydyn Date: Wed, 3 Nov 2021 00:06:11 +0200 Subject: [PATCH] [teammgrd]: Handle LAGs cleanup gracefully on Warm/Fast reboot. (#1934) Fixed LAGs cleanup on Warm/Fast reboot --- cfgmgr/teammgr.cpp | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/cfgmgr/teammgr.cpp b/cfgmgr/teammgr.cpp index b0e59c89a1be..ad8572e07b13 100644 --- a/cfgmgr/teammgr.cpp +++ b/cfgmgr/teammgr.cpp @@ -132,23 +132,44 @@ void TeamMgr::cleanTeamProcesses() std::string res; pid_t pid; + try { std::stringstream cmd; cmd << "cat " << shellquote("/var/run/teamd/" + alias + ".pid"); EXEC_WITH_ERROR_THROW(cmd.str(), res); + } + catch (const std::exception &e) + { + // Handle Warm/Fast reboot scenario + SWSS_LOG_NOTICE("Skipping non-existent port channel %s pid...", alias.c_str()); + continue; + } + try + { pid = static_cast(std::stoul(res, nullptr, 10)); aliasPidMap[alias] = pid; SWSS_LOG_INFO("Read port channel %s pid %d", alias.c_str(), pid); } + catch (const std::exception &e) + { + SWSS_LOG_ERROR("Failed to read port channel %s pid: %s", alias.c_str(), e.what()); + continue; + } + try { std::stringstream cmd; cmd << "kill -TERM " << pid; EXEC_WITH_ERROR_THROW(cmd.str(), res); - SWSS_LOG_INFO("Sent SIGTERM to port channel %s pid %d", alias.c_str(), pid); + SWSS_LOG_NOTICE("Sent SIGTERM to port channel %s pid %d", alias.c_str(), pid); + } + catch (const std::exception &e) + { + SWSS_LOG_ERROR("Failed to send SIGTERM to port channel %s pid %d: %s", alias.c_str(), pid, e.what()); + aliasPidMap.erase(alias); } }