@Override
  public void close() {
    if (closing) {
      return;
    }
    closing = true;
    sslEngine.closeOutbound();
    try {
      if (socketChannel.isConnected()) {
        if (!flush(netWriteBuffer)) {
          throw new IOException("Remaining data in the network buffer, can't send SSL close message.");
        }
        //prep the buffer for the close message
        netWriteBuffer.clear();
        //perform the close, since we called sslEngine.closeOutbound
        SSLEngineResult handshake = sslEngine.wrap(emptyBuf, netWriteBuffer);
        //we should be in a close state
        if (handshake.getStatus() != Status.CLOSED) {
          throw new IOException("Invalid close state, will not send network data.");
        }
        netWriteBuffer.flip();
        flush(netWriteBuffer);
      }
    } catch (IOException ie) {
      metrics.selectorCloseSocketErrorCount.inc();
      logger.debug("Failed to send SSL close message ", ie);
    } finally {
      try {
        release();
        clearReceive();
        clearSend();
        clearBuffers();
        socketChannel.socket().close();
        socketChannel.close();
      } catch (IOException ie) {
        metrics.selectorCloseSocketErrorCount.inc();
        logger.debug("Failed to close socket", ie);
      } finally {
        key.attach(null);
        key.cancel();
      }
    }
  }
Sends a SSL close message and closes socketChannel.
ambry-network/src/main/java/com/github/ambry/network/SSLTransmission.java