From 51b701eefeb2b34a5a85e470d4bf8f885ebfd1e1 Mon Sep 17 00:00:00 2001 From: Mikhail Bezoyan Date: Tue, 16 Jan 2024 22:38:50 +0000 Subject: [PATCH] [finagle-core] Fix for DeadlineFilter takes rejectWithdrawal regardless of passed Deadline Problem DeadlineFilter takes rejectWithdrawal regardless of passed Deadline https://github.com/twitter/finagle/issues/936 Solution Withdraw tokens only if the deadline has passed Closes twitter/finagle#936 Differential Revision: https://phabricator.twitter.biz/D1120240 --- CHANGELOG.rst | 5 +++++ .../scala/com/twitter/finagle/service/DeadlineFilter.scala | 6 +++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 639cab0f5b..02a3baa97f 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -7,6 +7,11 @@ Note that ``PHAB_ID=#`` and ``RB_ID=#`` correspond to associated messages in com Unreleased ---------- +Bug Fixes +~~~~~~~~~~ + +* finagle-core: Fix for DeadlineFilter takes rejectWithdrawal regardless of passed Deadline. ``PHAB_ID=D1120240`` + 23.11.0 ------- diff --git a/finagle-core/src/main/scala/com/twitter/finagle/service/DeadlineFilter.scala b/finagle-core/src/main/scala/com/twitter/finagle/service/DeadlineFilter.scala index f2946520fa..b2b0deb958 100644 --- a/finagle-core/src/main/scala/com/twitter/finagle/service/DeadlineFilter.scala +++ b/finagle-core/src/main/scala/com/twitter/finagle/service/DeadlineFilter.scala @@ -280,9 +280,6 @@ class DeadlineFilter[Req, Rep]( val now = Time.now val difference: Duration = deadline - now - val reject = rejectBucket.tryGet(rejectWithdrawal) - - trace(tracing, deadline, difference, reject) // If the difference is negative, we've exceeded the deadline if (difference.inMillis < 0l) { @@ -291,6 +288,8 @@ class DeadlineFilter[Req, Rep]( expiredTimeStat.add(exceeded.inMillis) // There are enough tokens to reject the request + val reject = rejectBucket.tryGet(rejectWithdrawal) + trace(tracing, deadline, difference, reject) if (reject) { rejectedCounter.incr() if (isDarkMode) @@ -304,6 +303,7 @@ class DeadlineFilter[Req, Rep]( service(request) } } else { + trace(tracing, deadline, difference, false) rejectBucket.put(serviceDeposit) val remaining = difference remainingTimeStat.add(remaining.inMillis)