-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
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
[Addons] RepositoryUpdater: fix time calculation overflow #26531
Conversation
The proposed change should work, but how about a solution using diffdiff --git a/xbmc/addons/RepositoryUpdater.cpp b/xbmc/addons/RepositoryUpdater.cpp
index c8c1dcbcc32..cd4a7e6b224 100644
--- a/xbmc/addons/RepositoryUpdater.cpp
+++ b/xbmc/addons/RepositoryUpdater.cpp
@@ -313,6 +313,8 @@ CDateTime CRepositoryUpdater::ClosestNextCheck() const
void CRepositoryUpdater::ScheduleUpdate(UpdateScheduleType scheduleType)
{
+ using namespace std::chrono;
+
std::unique_lock<CCriticalSection> lock(m_criticalSection);
m_timer.Stop(true);
@@ -322,14 +324,16 @@ void CRepositoryUpdater::ScheduleUpdate(UpdateScheduleType scheduleType)
if (!m_addonMgr.HasAddons(AddonType::REPOSITORY))
return;
- int delta{1};
+ milliseconds delta{1};
const auto nextCheck = ClosestNextCheck();
if (nextCheck.IsValid())
{
- // Repos were already checked once and we know when to check next
- delta = std::max(1, (nextCheck - CDateTime::GetCurrentDateTime()).GetSecondsTotal() * 1000);
- CLog::Log(LOGDEBUG, "CRepositoryUpdater: closest next update check at {} (in {} s)",
- nextCheck.GetAsLocalizedDateTime(), delta / 1000);
+ // Repos were already checked once and we know when to check next.
+ // delta must be positive and not zero (m_timer.Start() ignores 0 wait time)
+ delta = std::max<milliseconds>(
+ delta, seconds((nextCheck - CDateTime::GetCurrentDateTime()).GetSecondsTotal()));
+ CLog::Log(LOGDEBUG, "CRepositoryUpdater: closest next update check at {} (in {})",
+ nextCheck.GetAsLocalizedDateTime(), duration_cast<seconds>(delta));
}
if (scheduleType == UpdateScheduleType::Regular)
@@ -337,17 +341,12 @@ void CRepositoryUpdater::ScheduleUpdate(UpdateScheduleType scheduleType)
// Enforce minimum hold-off time of 1 hour between regular updates - this is especially
// important to handle all sorts of failure cases (e.g., failure to update the add-on database)
// that would otherwise lead to an immediate new update attempt and continuous hammering of the servers.
- delta = std::max(1 * 60 * 60 * 1'000, delta);
- }
- else
- {
- // delta must be positive and not zero (m_timer.Start() ignores 0 wait time)
- delta = std::max(1, delta);
+ delta = std::max<milliseconds>(hours(1), delta);
}
- CLog::Log(LOGDEBUG, "CRepositoryUpdater: checking in {} ms", delta);
+ CLog::Log(LOGDEBUG, "CRepositoryUpdater: checking in {}", delta);
- if (!m_timer.Start(std::chrono::milliseconds(delta)))
+ if (!m_timer.Start(delta))
CLog::Log(LOGERROR,"CRepositoryUpdater: failed to start timer");
}
} Switching to |
010e72c
to
94dc183
Compare
Sure, when it does compile :) Do you recommend updating the backport too? |
Using (32 bit) int for ms calculation lead to (negative) overflow when more than ~25 days ago. Use std::chrono increase time span
94dc183
to
d24da28
Compare
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.
Thanks, looks good to me now 👍
Once merged please update the backport to match this PR.
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.
Thanks.
Backport is updated. |
Description
Using (32 bit) int for ms calculation lead to (negative) overflow when more than ~25 days ago. Using
secondsstd::chrono increase time span to ~68 years.Motivation and context
When updating a LE13 test installation after a few weeks no addon updates were shown. The log looked odd:
How has this been tested?
PR included in LE13 build successfully tested on previous failing Addon33.db
What is the effect on users?
Working addon updates.
Screenshots (if appropriate):
Types of change
Checklist: