From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lf1-f68.google.com (mail-lf1-f68.google.com [209.85.167.68]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 79C87445320 for ; Tue, 14 Jul 2020 17:54:02 +0300 (MSK) Received: by mail-lf1-f68.google.com with SMTP id t9so11874001lfl.5 for ; Tue, 14 Jul 2020 07:54:02 -0700 (PDT) Date: Tue, 14 Jul 2020 17:53:58 +0300 From: Cyrill Gorcunov Message-ID: <20200714145358.GG296695@grain> References: <20200714144440.551127-1-gorcunov@gmail.com> <20200714144440.551127-5-gorcunov@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200714144440.551127-5-gorcunov@gmail.com> Subject: [Tarantool-patches] [PATCH v2 4/4] qsync: don't send negative timeouts into fiber_cond_wait_timeout List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Vladislav Shpilevoy Cc: tml Basically our timeout is calculated via (a - b), where @a is a constant positive value fetched once, in turn the @b is rather a dynamic value thus the result may be negative. libev uses assert() call to catch such values when passed to timers setup. Thus lets intercept potential assert() trigger and exit early if timeout is already expired. Signed-off-by: Cyrill Gorcunov --- There were a typo, so I force-updated the branch src/box/txn_limbo.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/box/txn_limbo.c b/src/box/txn_limbo.c index d5b887d36..0924952b7 100644 --- a/src/box/txn_limbo.c +++ b/src/box/txn_limbo.c @@ -174,8 +174,10 @@ txn_limbo_wait_complete(struct txn_limbo *limbo, struct txn_limbo_entry *entry) double start_time = fiber_clock(); while (true) { double deadline = start_time + replication_synchro_timeout; - bool cancellable = fiber_set_cancellable(false); double timeout = deadline - fiber_clock(); + if (timeout < 0) + goto do_rollback; + bool cancellable = fiber_set_cancellable(false); int rc = fiber_cond_wait_timeout(&limbo->wait_cond, timeout); fiber_set_cancellable(cancellable); if (txn_limbo_entry_is_complete(entry)) @@ -509,8 +511,10 @@ txn_limbo_wait_confirm(struct txn_limbo *limbo) double start_time = fiber_clock(); while (true) { double deadline = start_time + replication_synchro_timeout; - bool cancellable = fiber_set_cancellable(false); double timeout = deadline - fiber_clock(); + if (timeout < 0) + goto timed_out; + bool cancellable = fiber_set_cancellable(false); int rc = fiber_cond_wait_timeout(&limbo->wait_cond, timeout); fiber_set_cancellable(cancellable); if (cwp.is_confirm || cwp.is_rollback) -- 2.26.2