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); } }