From a5fdbeef1619f0171f05b45c867d00e86efdc029 Mon Sep 17 00:00:00 2001 From: Michael Graeb Date: Mon, 6 May 2024 16:49:48 -0700 Subject: [PATCH] Fix aws_future_wait() with UINT64_MAX timeout --- source/future.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/source/future.c b/source/future.c index be213184b..96c88ef6a 100644 --- a/source/future.c +++ b/source/future.c @@ -453,13 +453,16 @@ bool aws_future_impl_wait(const struct aws_future_impl *future, uint64_t timeout /* this function is conceptually const, but we need to use synchronization primitives */ struct aws_future_impl *mutable_future = (struct aws_future_impl *)future; + /* condition-variable takes signed timeout, so clamp to INT64_MAX (292+ years) */ + int64_t timeout_i64 = aws_min_u64(timeout_ns, INT64_MAX); + /* BEGIN CRITICAL SECTION */ aws_mutex_lock(&mutable_future->lock); bool is_done = aws_condition_variable_wait_for_pred( &mutable_future->wait_cvar, &mutable_future->lock, - (int64_t)timeout_ns, + timeout_i64, s_future_impl_is_done_pred, mutable_future) == AWS_OP_SUCCESS;