diff options
| author | Julian Andres Klode <julian.klode@canonical.com> | 2025-02-10 19:56:16 +0100 |
|---|---|---|
| committer | Julian Andres Klode <julian.klode@canonical.com> | 2025-02-14 19:04:56 +0100 |
| commit | a9587b39ea6776b1d1324288786176102f65cee5 (patch) | |
| tree | d475c30cddec0d15343a3fab9a5ed9b3a1fbe402 /apt-pkg | |
| parent | 222271ee0d44c8e7bc00935fbbc2615529a4cdfc (diff) | |
solver3: Implement a timeout, default 10s
A SAT solver can run more or less forever, but that's not a good
user experience.
Diffstat (limited to 'apt-pkg')
| -rw-r--r-- | apt-pkg/solver3.cc | 8 | ||||
| -rw-r--r-- | apt-pkg/solver3.h | 5 |
2 files changed, 12 insertions, 1 deletions
diff --git a/apt-pkg/solver3.cc b/apt-pkg/solver3.cc index b4a69d844..d363cdee7 100644 --- a/apt-pkg/solver3.cc +++ b/apt-pkg/solver3.cc @@ -32,8 +32,9 @@ #include <apt-pkg/solver3.h> #include <apt-pkg/version.h> -#include <algorithm> #include <cassert> +#include <chrono> +#include <ctime> #include <sstream> // FIXME: Helpers stolen from DepCache, please give them back. @@ -740,6 +741,10 @@ bool APT::Solver::Pop() for (std::string msg; _error->PopMessage(msg);) std::cerr << "Branch failed: " << msg << std::endl; + time_t now = time(nullptr); + if (now - startTime >= Timeout) + return _error->Error("Solver timed out."); + _error->RevertToStack(); assert(choices.back() < solved.size()); @@ -834,6 +839,7 @@ void APT::Solver::RescoreWorkIfNeeded() bool APT::Solver::Solve() { + startTime = time(nullptr); while (true) { while (not Propagate()) diff --git a/apt-pkg/solver3.h b/apt-pkg/solver3.h index 34da03ea0..da75179d5 100644 --- a/apt-pkg/solver3.h +++ b/apt-pkg/solver3.h @@ -213,6 +213,9 @@ class Solver // This is an index into the solved vector. std::vector<depth_type> choices{}; + // \brief The time we called Solve() + time_t startTime; + /// Various configuration options // \brief Debug level int debug{_config->FindI("Debug::APT::Solver")}; @@ -232,6 +235,8 @@ class Solver bool FixPolicyBroken{_config->FindB("APT::Get::Fix-Policy-Broken")}; // \brief If set, we use strict pinning. bool DeferVersionSelection{_config->FindB("APT::Solver::Defer-Version-Selection", true)}; + // \brief If set, we use strict pinning. + int Timeout{_config->FindI("APT::Solver::Timeout", 10)}; // \brief Discover a variable, translating the underlying dependencies to the SAT presentation // |
