-
Notifications
You must be signed in to change notification settings - Fork 21
Handle Sighup #11
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
Handle Sighup #11
Conversation
|
@shishirb-MSFT This is a reupload of the previous pr, unfortunately when we created the snapshot the PR did not get copied over, mind re-reviewing? #Closed |
| _adminConfigs.Refresh(); | ||
| } | ||
|
|
||
|
|
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.
nit: space #Closed
| JsonParser::JsonParser(const std::string& jsonFilePath, bool alwaysCreateFile) : | ||
| _jsonFilePath(jsonFilePath) | ||
| { | ||
| if (!boost::filesystem::exists(_jsonFilePath) && alwaysCreateFile) |
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.
alwaysCreateFile [](start = 53, length = 16)
Check alwaysCreateFile first (cheaper) in the conditional. Same comment for the force check on line 28. #Closed
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.
It's okay but curious why you chose to split into separate if statements rather than combine with &&.
In reply to: 594671740 [](ancestors = 594671740)
|
|
||
| void DownloadManager::RefreshConfigs() const | ||
| { | ||
| _taskThread.SchedBlock([&]() |
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.
SchedBlock [](start = 16, length = 10)
No need to block, so use Sched() with 'this' as the tag. #Closed
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.
Should be SchedImmediate() so downloads immediately get the new configs I think
In reply to: 594674119 [](ancestors = 594674119)
client-lite/src/exe/docs.cpp
Outdated
| { | ||
| break; | ||
| } | ||
| if (_refreshEvent.IsSignaled()) |
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.
_refreshEvent [](start = 16, length = 13)
Combining the event signaled check with the idle loop means we still have a delay in reading config values.
Instead, accept fnRefreshConfigs in the constructor and store it as a static member and call it from _SignalHandler directly. #Resolved
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.
I did some additional refactoring that might make the class more flexible if we need to support other signals, but let me know what you think
In reply to: 594676272 [](ancestors = 594676272)
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.
It's strange to have a callback function go back into the caller to achieve its task. It is more straightforward to have ProcessController itself handle the shutdown in this case.
Moreover, you now have two copies of the lambda to handle SIGINT and SIGTERM.
In general, refactoring early to support a future unknown requirement is not always good because you never know whether the change as it is today will apply to that requirement.
In reply to: 595355095 [](ancestors = 595355095,594676272)
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.
client-lite/src/exe/docs.cpp
Outdated
| DoLogInfo("Received signal %d. Initiating shutdown.", signalNumber); | ||
| _shutdownEvent.SetEvent(); | ||
| } | ||
| if (signalNumber == SIGHUP) |
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.
if [](start = 8, length = 2)
else if #Closed
| DownloadStatus GetDownloadStatus(const std::string& downloadId) const; | ||
|
|
||
| bool IsIdle() const; | ||
| void RefreshConfigs() const; |
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.
RefreshConfigs [](start = 9, length = 14)
RefreshAdminConfigs - to be clear and consistent. #Closed
| #include <unordered_map> | ||
| #include "ban_list.h" | ||
|
|
||
| class ConfigManager; |
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.
ConfigManager [](start = 6, length = 13)
fwd declaration should be enough here #Closed
client-lite/src/exe/docs.cpp
Outdated
| using namespace std::chrono_literals; // NOLINT(build/namespaces) how else should we use chrono literals? | ||
|
|
||
| class ProcessController | ||
| class ProcessController : DONonCopyable |
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.
: DONonCopyable [](start = 24, length = 15)
Perhaps there is no need to make this a singleton as there are no non-static members #Resolved
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.
Non-copyable doesn't make it a singleton because you can create multiple instances of this class.
In reply to: 595354139 [](ancestors = 595354139)
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.
Ah right, there's a convention for singleton involving static instance of the class itself and a private constructor
In reply to: 595411879 [](ancestors = 595411879,595354139)
|
|
||
| void DownloadManager::RefreshAdminConfigs() const | ||
| { | ||
| _taskThread.SchedImmediate([&]() |
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.
& [](start = 32, length = 1)
Capture 'this' instead. The capture-all option is generally discouraged because it will capture more stuff than is needed. There's nothing other than 'this' to capture here but better to get used to that practice. #Closed
client-lite/src/exe/docs.cpp
Outdated
| else if (signalNumber == SIGHUP) | ||
| { | ||
| _sighupHandler = std::move(fnHandler); | ||
| } |
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.
} [](start = 8, length = 1)
Depending on how this will change based on my refactoring comment, add an else case here with DO_ASSERT(false). #Resolved
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.
Think I'll revert the changes and just make the constructor accept the callback for refreshing configs
In reply to: 595419554 [](ancestors = 595419554)
client-lite/src/exe/docs.cpp
Outdated
| { | ||
| public: | ||
| ProcessController() | ||
| ProcessController(std::function<void()>& fnRefreshConfigs) |
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.
& [](start = 43, length = 1)
Since you are using std::move, use && here #Closed
client-lite/src/exe/docs.cpp
Outdated
| DoLogInfo("Started, %s", msdoutil::ComponentVersion().c_str()); | ||
|
|
||
| ProcessController procController; | ||
| std::function<void()> fnRefreshConfigs = [&downloadManager]() |
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.
std::function<void()> [](start = 0, length = 25)
Can use auto here but consider writing the lambda inline on line 111. It will also satisfy the && parameter type. #Closed
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.
Right, able to write inline due to parameter type being an rvalue reference with the change to use && above
In reply to: 595575443 [](ancestors = 595575443)
|
Verified this change works on iteration 5. With do plugin installed, did an apt install of npm and verified through logging that client configs were refreshed, bad mcc host was banned, and download finished succesfully. #Closed |
shishirb-MSFT
left a comment
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.
![]()
No description provided.