|
46 | 46 | import java.util.concurrent.CancellationException;
|
47 | 47 | import java.util.concurrent.Executor;
|
48 | 48 | import java.util.concurrent.ScheduledExecutorService;
|
49 |
| -import java.util.concurrent.ScheduledFuture; |
50 | 49 | import java.util.concurrent.TimeUnit;
|
51 | 50 | import javax.annotation.Nullable;
|
52 | 51 |
|
@@ -122,11 +121,6 @@ final class HttpJsonClientCallImpl<RequestT, ResponseT>
|
122 | 121 | @GuardedBy("lock")
|
123 | 122 | private volatile boolean closed;
|
124 | 123 |
|
125 |
| - // Store the timeout future created by the deadline schedule executor. The future |
126 |
| - // can be cancelled if a response has been received before the timeout. |
127 |
| - @GuardedBy("lock") |
128 |
| - private ScheduledFuture<?> timeoutFuture; |
129 |
| - |
130 | 124 | HttpJsonClientCallImpl(
|
131 | 125 | ApiMethodDescriptor<RequestT, ResponseT> methodDescriptor,
|
132 | 126 | String endpoint,
|
@@ -173,20 +167,16 @@ public void start(Listener<ResponseT> responseListener, HttpJsonMetadata request
|
173 | 167 | Preconditions.checkState(this.listener == null, "The call is already started");
|
174 | 168 | this.listener = responseListener;
|
175 | 169 | this.requestHeaders = requestHeaders;
|
| 170 | + } |
176 | 171 |
|
177 |
| - // Use the timeout duration value instead of calculating the future Instant |
178 |
| - // Only schedule the deadline if the RPC timeout has been set in the RetrySettings |
179 |
| - Duration timeout = callOptions.getTimeout(); |
180 |
| - if (timeout != null) { |
181 |
| - // The future timeout value is guaranteed to not be a negative value as the |
182 |
| - // RetryAlgorithm will not retry |
183 |
| - long timeoutMs = timeout.toMillis(); |
184 |
| - // Assign the scheduled future so that it can be cancelled if the timeout task |
185 |
| - // is not needed (response received prior to timeout) |
186 |
| - timeoutFuture = |
187 |
| - this.deadlineCancellationExecutor.schedule( |
188 |
| - this::timeout, timeoutMs, TimeUnit.MILLISECONDS); |
189 |
| - } |
| 172 | + // Use the timeout duration value instead of calculating the future Instant |
| 173 | + // Only schedule the deadline if the RPC timeout has been set in the RetrySettings |
| 174 | + Duration timeout = callOptions.getTimeout(); |
| 175 | + if (timeout != null) { |
| 176 | + // The future timeout value is guaranteed to not be a negative value as the |
| 177 | + // RetryAlgorithm will not retry |
| 178 | + long timeoutMs = timeout.toMillis(); |
| 179 | + this.deadlineCancellationExecutor.schedule(this::timeout, timeoutMs, TimeUnit.MILLISECONDS); |
190 | 180 | }
|
191 | 181 | }
|
192 | 182 |
|
@@ -440,14 +430,6 @@ private void close(
|
440 | 430 | return;
|
441 | 431 | }
|
442 | 432 | closed = true;
|
443 |
| - |
444 |
| - // Cancel the timeout future if there is a timeout task created |
445 |
| - if (timeoutFuture != null) { |
446 |
| - // timeout() invokes close(), but cancelling a completed task should no-op |
447 |
| - timeoutFuture.cancel(true); |
448 |
| - timeoutFuture = null; |
449 |
| - } |
450 |
| - |
451 | 433 | // Best effort task cancellation (to not be confused with task's thread interruption).
|
452 | 434 | // If the task is in blocking I/O waiting for the server response, it will keep waiting for
|
453 | 435 | // the response from the server, but once response is received the task will exit silently.
|
|
0 commit comments