GitFileDiffCacheImpl: cancel tasks failing due to timeout or interrupt

This avoids the task continues consuming resources unnecessarily. This
may help to avoid unnecessary computations and return the thread
executing the task earlier to the ExecutorService where it can be used
to schedule other tasks waiting for an execution thread.

Release-Notes: GitFileDiffCacheImpl: cancel tasks failing due to timeout or interrupt
Change-Id: I09042d5a32375c2762d0152a24a57bdda66e34b3
(cherry picked from commit c30f11fee03edfcd5f1c4cc7dca8203efe422ead)
diff --git a/java/com/google/gerrit/server/patch/gitfilediff/GitFileDiffCacheImpl.java b/java/com/google/gerrit/server/patch/gitfilediff/GitFileDiffCacheImpl.java
index 013a596..30153c0 100644
--- a/java/com/google/gerrit/server/patch/gitfilediff/GitFileDiffCacheImpl.java
+++ b/java/com/google/gerrit/server/patch/gitfilediff/GitFileDiffCacheImpl.java
@@ -376,6 +376,7 @@
         // if the algorithm used in diffs is HISTOGRAM_WITH_FALLBACK_MYERS.
         return fileDiffFuture.get(timeoutMillis, TimeUnit.MILLISECONDS);
       } catch (InterruptedException | TimeoutException e) {
+        fileDiffFuture.cancel(true);
         // If timeout happens, create a negative result
         logger.atFine().log(
             "computing git file diff for %s with %s as diff algorithm failed with a timeout,"