-
Notifications
You must be signed in to change notification settings - Fork 61
Do not provision if primary times out while connecting to secon… #1491
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -122,11 +122,14 @@ int main(int argc, char *argv[]) { | |
conn = aktualizr.SetSignalHandler(f_cb); | ||
|
||
if (!config.uptane.secondary_config_file.empty()) { | ||
if (boost::filesystem::exists(config.uptane.secondary_config_file)) { | ||
try { | ||
Primary::initSecondaries(aktualizr, config.uptane.secondary_config_file); | ||
} else { | ||
LOG_WARNING << "The specified secondary config file does not exist: " << config.uptane.secondary_config_file | ||
<< "\nProceed further without secondary(ies)"; | ||
} catch (const std::exception &e) { | ||
LOG_ERROR << "Secondary initialization failed"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would add e.what() to the log message so we see more details of the secondary provisioning failure. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the current version, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see, makes sense, it's up to you whether to terminate exceptions in initSecondaries and return boolean or rethrow them. |
||
if (!aktualizr.IsRegistered()) { | ||
LOG_ERROR << "Cannot provision without all secondaries present, exiting..."; | ||
return EXIT_FAILURE; | ||
} | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,8 +57,7 @@ void initSecondaries(Aktualizr& aktualizr, const boost::filesystem::path& config | |
} | ||
} catch (const std::exception& exc) { | ||
LOG_ERROR << "Failed to initialize a secondary: " << exc.what(); | ||
LOG_ERROR << "Continue with initialization of the remaining secondaries, if any left."; | ||
// otherwise rethrow the exception | ||
throw exc; | ||
} | ||
} | ||
} | ||
|
@@ -71,7 +70,7 @@ class SecondaryWaiter { | |
timer_{io_context_}, | ||
connected_secondaries_(secondaries) {} | ||
|
||
void addSecoondary(const std::string& ip, uint16_t port) { secondaries_to_wait_for_.insert(key(ip, port)); } | ||
void addSecondary(const std::string& ip, uint16_t port) { secondaries_to_wait_for_.insert(key(ip, port)); } | ||
|
||
void wait() { | ||
if (secondaries_to_wait_for_.empty()) { | ||
|
@@ -82,8 +81,10 @@ class SecondaryWaiter { | |
timer_.async_wait([&](const boost::system::error_code& error_code) { | ||
if (!!error_code) { | ||
LOG_ERROR << "Wait for secondaries has failed: " << error_code; | ||
throw std::runtime_error("Error while waiting for secondary"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As an alternative to these two 'throws' just one throw can be added at the end of createIPSecondaries(). |
||
} else { | ||
LOG_ERROR << "Timeout while waiting for secondaries: " << error_code; | ||
LOG_ERROR << "Timeout while waiting for secondary: " << error_code; | ||
throw std::runtime_error("Timeout while waiting for secondary"); | ||
} | ||
io_context_.stop(); | ||
}); | ||
|
@@ -149,7 +150,7 @@ static Secondaries createIPSecondaries(const IPSecondariesConfig& config) { | |
if (sec_creation_res.first) { | ||
result.push_back(sec_creation_res.second); | ||
} else { | ||
sec_waiter.addSecoondary(ip_sec_cfg.ip, ip_sec_cfg.port); | ||
sec_waiter.addSecondary(ip_sec_cfg.ip, ip_sec_cfg.port); | ||
} | ||
} | ||
|
||
|
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.
This try/catch was not necessary as this code is already wrapped by the outter try/catch.
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.
The exception is ignored if
aktualizr.IsRegistered()
, I think we cannot rely on the outer try/catch in this case.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.
ok. I see, this is for the use case when Primary and Secondaries are trying to connect to each other after a device has been already provisioned, e.g. just a device and/or aktualizr reboot. I think, it might be not an optimal strategy to exit the connection procedure on a first failure if a device has been already registered, but, I suppose, it's not so important, adding secondaries dynamically is more important or not trying to connect to them on a startup at all if a device already registered.
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.
That's a good point indeed... But I remember I chose this simple solution at first because right now, we can't really do better than what the IP secondaries config parser gives us and it handles all IP secondaries at once.