private void discardResponses() {
    logger.trace("Discarding responses on account of shutdown");
    RestServiceException e = new RestServiceException("Service shutdown", RestServiceErrorCode.ServiceUnavailable);
    if (responses.size() > 0) {
      int noOfResponses = responses.size();
      logger.info("There were {} responses in flight during was shut down", noOfResponses);
      metrics.residualResponseSetSize.inc(noOfResponses);
      List<ResponseWriteCallback> callbacks = new LinkedList<ResponseWriteCallback>();
      // Since the callbacks remove the hash map entry, we need to call them when we are *not* iterating over the map.
      // Unfortunately this creates two traversals. But this should be ok as this happens during shutdown and does
      // not affect live performance.
      for (Map.Entry<RestRequest, ResponseWriteCallback> response : responses.entrySet()) {
        callbacks.add(response.getValue());
      }
      for (ResponseWriteCallback callback : callbacks) {
        callback.onCompletion(0L, e);
      }
    }
  }
Called on shutdown and fails the remaining responses and releases resources held by them.
ambry-rest/src/main/java/com/github/ambry/rest/AsyncRequestResponseHandler.java