You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by cf...@apache.org on 2021/10/16 10:34:52 UTC
[mesos] branch master updated: Fix Timeout overflow issue caused by
negative duration
This is an automated email from the ASF dual-hosted git repository.
cfnatali pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mesos.git
The following commit(s) were added to refs/heads/master by this push:
new 7bcb391 Fix Timeout overflow issue caused by negative duration
7bcb391 is described below
commit 7bcb39144bc0969cf6ec040f0d9ce9a52d2a4345
Author: Hao Su <75...@users.noreply.github.com>
AuthorDate: Fri Oct 1 09:15:45 2021 -0700
Fix Timeout overflow issue caused by negative duration
---
3rdparty/libprocess/include/process/timeout.hpp | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/3rdparty/libprocess/include/process/timeout.hpp b/3rdparty/libprocess/include/process/timeout.hpp
index 918e5b8..a84c08b 100644
--- a/3rdparty/libprocess/include/process/timeout.hpp
+++ b/3rdparty/libprocess/include/process/timeout.hpp
@@ -34,10 +34,20 @@ public:
// from now.
static Timeout in(const Duration& duration)
{
+ Time now = Clock::now();
+ if (duration < Duration::zero()) {
+ // If duration is negative, we need now() + duration > Duration::min() to avoid overflow.
+ // Therefore, we check for now() > duration::min() - duration.
+ if (now.duration() > Duration::min() - duration) {
+ return Timeout(now + duration);
+ }
+ return Timeout(Time::epoch());
+ }
+
// We need now() + duration < Duration::max() to avoid overflow.
// Therefore, we check for now() < duration::max() - duration.
- if (Clock::now().duration() < Duration::max() - duration) {
- return Timeout(Clock::now() + duration);
+ if (now.duration() < Duration::max() - duration) {
+ return Timeout(now + duration);
}
return Timeout(Time::max());