-
Notifications
You must be signed in to change notification settings - Fork 694
Add a delay between killing teamd processes #3325
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 20 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
e5683d5
Add a delay between killing teamd processes
saiarcot895 f4fd3ab
Update LAG removal code to use the same logic as cleaning up all LAGs
saiarcot895 7b6fc53
Update tests to test LAG cleanup and to test with the new code
saiarcot895 27f6d3c
Merge remote-tracking branch 'origin/master' into teamd-delay-kill
saiarcot895 bdd47c7
Merge remote-tracking branch 'origin/master' into teamd-delay-kill
saiarcot895 c5d84cf
Add more tests to cover more cases
saiarcot895 1dd20a0
Merge branch 'master' into teamd-delay-kill
dgsudharsan 8f71480
Merge branch 'master' into teamd-delay-kill
dgsudharsan f39d60f
Merge branch 'master' into teamd-delay-kill
dgsudharsan e7ce08d
Wait 200ms instead of 100ms, and fix teamd wait code
saiarcot895 ce1fdae
Merge remote-tracking branch 'refs/remotes/personal/teamd-delay-kill'…
saiarcot895 726f800
Merge remote-tracking branch 'origin/master' into teamd-delay-kill
saiarcot895 d2ccbb3
Merge remote-tracking branch 'origin/master' into teamd-delay-kill
saiarcot895 181bdb9
Merge branch 'master' into teamd-delay-kill
saiarcot895 4d99bf4
Merge branch 'master' into teamd-delay-kill
saiarcot895 6472d33
Merge branch 'master' into teamd-delay-kill
dgsudharsan fff96a3
Merge branch 'master' into teamd-delay-kill
saiarcot895 cd38a76
Merge branch 'master' into teamd-delay-kill
judyjoseph 9f6ab64
Try 10ms sleep
saiarcot895 9aaf399
Merge remote-tracking branch 'origin/master' into teamd-delay-kill
saiarcot895 702ffda
Fix code style
saiarcot895 a4a5d83
Merge remote-tracking branch 'origin/master' into teamd-delay-kill
saiarcot895 e4b838b
Some more coding style fixes
saiarcot895 3adfe66
Merge branch 'master' into teamd-delay-kill
saiarcot895 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,6 +16,8 @@ | |
| #include <net/if.h> | ||
| #include <sys/ioctl.h> | ||
| #include <sys/stat.h> | ||
| #include <sys/wait.h> | ||
| #include <sys/types.h> | ||
| #include <signal.h> | ||
|
|
||
|
|
||
|
|
@@ -171,18 +173,26 @@ void TeamMgr::cleanTeamProcesses() | |
| SWSS_LOG_ENTER(); | ||
| SWSS_LOG_NOTICE("Cleaning up LAGs during shutdown..."); | ||
|
|
||
| std::unordered_map<std::string, pid_t> aliasPidMap; | ||
| std::unordered_map<std::string, int> aliasPidMap; | ||
|
|
||
| for (const auto& alias: m_lagList) | ||
| { | ||
| std::string res; | ||
| pid_t pid; | ||
| // Sleep for 10 milliseconds so as to not overwhelm the netlink | ||
| // socket buffers with events about interfaces going down | ||
| std::this_thread::sleep_for(std::chrono::milliseconds(10)); | ||
|
|
||
| try | ||
| { | ||
| std::stringstream cmd; | ||
| cmd << "cat " << shellquote("/var/run/teamd/" + alias + ".pid"); | ||
| EXEC_WITH_ERROR_THROW(cmd.str(), res); | ||
| ifstream pidFile("/var/run/teamd/" + alias + ".pid"); | ||
| if (pidFile.is_open()) { | ||
| pidFile >> pid; | ||
| aliasPidMap[alias] = pid; | ||
| SWSS_LOG_INFO("Read port channel %s pid %d", alias.c_str(), pid); | ||
| } else { | ||
| SWSS_LOG_NOTICE("Unable to read pid file for %s, skipping...", alias.c_str()); | ||
| continue; | ||
| } | ||
| } | ||
| catch (const std::exception &e) | ||
| { | ||
|
|
@@ -191,31 +201,11 @@ void TeamMgr::cleanTeamProcesses() | |
| continue; | ||
| } | ||
|
|
||
| try | ||
| { | ||
| pid = static_cast<pid_t>(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_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()); | ||
| if (kill(pid, SIGTERM)) { | ||
| SWSS_LOG_ERROR("Failed to send SIGTERM to port channel %s pid %d: %s", alias.c_str(), pid, strerror(errno)); | ||
| aliasPidMap.erase(alias); | ||
| } else { | ||
| SWSS_LOG_NOTICE("Sent SIGTERM to port channel %s pid %d", alias.c_str(), pid); | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -224,13 +214,11 @@ void TeamMgr::cleanTeamProcesses() | |
| const auto &alias = cit.first; | ||
| const auto &pid = cit.second; | ||
|
|
||
| std::stringstream cmd; | ||
| std::string res; | ||
|
|
||
| SWSS_LOG_NOTICE("Waiting for port channel %s pid %d to stop...", alias.c_str(), pid); | ||
|
|
||
| cmd << "tail -f --pid=" << pid << " /dev/null"; | ||
| EXEC_WITH_ERROR_THROW(cmd.str(), res); | ||
| while (!kill(pid, 0)) { | ||
| std::this_thread::sleep_for(std::chrono::milliseconds(10)); | ||
| } | ||
| } | ||
|
|
||
| SWSS_LOG_NOTICE("LAGs cleanup is done"); | ||
|
|
@@ -658,42 +646,21 @@ bool TeamMgr::removeLag(const string &alias) | |
| { | ||
| SWSS_LOG_ENTER(); | ||
|
|
||
| stringstream cmd; | ||
| 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) | ||
| { | ||
| SWSS_LOG_NOTICE("Failed to remove non-existent port channel %s pid...", alias.c_str()); | ||
| return false; | ||
| } | ||
|
|
||
| try | ||
| { | ||
| pid = static_cast<pid_t>(std::stoul(res, nullptr, 10)); | ||
| 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()); | ||
| return false; | ||
| ifstream pidfile("/var/run/teamd/" + alias + ".pid"); | ||
| if (pidfile.is_open()) { | ||
|
||
| pidfile >> pid; | ||
| SWSS_LOG_INFO("Read port channel %s pid %d", alias.c_str(), pid); | ||
| } else { | ||
| SWSS_LOG_NOTICE("Failed to remove non-existent port channel %s pid...", alias.c_str()); | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| try | ||
| { | ||
| std::stringstream cmd; | ||
| cmd << "kill -TERM " << pid; | ||
| EXEC_WITH_ERROR_THROW(cmd.str(), res); | ||
| } | ||
| 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()); | ||
| if (kill(pid, SIGTERM)) { | ||
| SWSS_LOG_ERROR("Failed to send SIGTERM to port channel %s pid %d: %s", alias.c_str(), pid, strerror(errno)); | ||
| return false; | ||
| } | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
{-> new line