From bbe2cfb7437ca37ffdcc3d4522c29c30c9eef75c Mon Sep 17 00:00:00 2001 From: brido4125 Date: Thu, 10 Aug 2023 11:57:30 +0900 Subject: [PATCH] FIX: Infinity waiting with get method in BulkGetFuture. --- .../net/spy/memcached/internal/BulkGetFuture.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/main/java/net/spy/memcached/internal/BulkGetFuture.java b/src/main/java/net/spy/memcached/internal/BulkGetFuture.java index f9b87efd1..1f6b204d3 100644 --- a/src/main/java/net/spy/memcached/internal/BulkGetFuture.java +++ b/src/main/java/net/spy/memcached/internal/BulkGetFuture.java @@ -32,6 +32,8 @@ import net.spy.memcached.ops.Operation; import net.spy.memcached.ops.OperationState; +import static net.spy.memcached.DefaultConnectionFactory.DEFAULT_OPERATION_TIMEOUT; + /** * Future for handling results from bulk gets. * @@ -43,7 +45,7 @@ public class BulkGetFuture implements BulkFuture> { private final Map> rvMap; private final Collection ops; private final CountDownLatch latch; - private boolean timeout = false; + private boolean isTimeout = false; public BulkGetFuture(Map> m, Collection getOps, CountDownLatch l) { @@ -72,7 +74,7 @@ public boolean cancel(boolean ign) { @Override public Map get() throws InterruptedException, ExecutionException { try { - return get(Long.MAX_VALUE, TimeUnit.MILLISECONDS); + return get(DEFAULT_OPERATION_TIMEOUT * ops.size(), TimeUnit.MILLISECONDS); } catch (TimeoutException e) { throw new OperationTimeoutException(e); } @@ -84,7 +86,7 @@ public Map getSome(long duration, TimeUnit units) Collection timedoutOps = new HashSet(); Map ret = internalGet(duration, units, timedoutOps); if (timedoutOps.size() > 0) { - timeout = true; + isTimeout = true; LoggerFactory.getLogger(getClass()).warn( new CheckedOperationTimeoutException(duration, units, timedoutOps).getMessage()); } @@ -104,7 +106,7 @@ public Map get(long duration, TimeUnit units) Collection timedoutOps = new HashSet(); Map ret = internalGet(duration, units, timedoutOps); if (timedoutOps.size() > 0) { - this.timeout = true; + this.isTimeout = true; throw new CheckedOperationTimeoutException(duration, units, timedoutOps); } return ret; @@ -177,6 +179,6 @@ private Map internalGet(long to, TimeUnit unit, * @see net.spy.memcached.internal.BulkFuture#isTimeout() */ public boolean isTimeout() { - return timeout; + return isTimeout; } }