synchronized void cancel(IndexShard shard, String reason) {
   final ShardRecoveryContext shardRecoveryContext = ongoingRecoveries.get(shard);
   if (shardRecoveryContext != null) {
     final List<Exception> failures = new ArrayList<>();
     for (RecoverySourceHandler handlers : shardRecoveryContext.recoveryHandlers) {
       try {
         handlers.cancel(reason);
       } catch (Exception ex) {
         failures.add(ex);
       } finally {
         shard.recoveryStats().decCurrentAsSource();
       }
     }
     ExceptionsHelper.maybeThrowRuntimeAndSuppress(failures);
   }
 }