@Override
          public void run() {
            try {
              socket.setSoTimeout(3000);
              DataInputStream input = new DataInputStream(socket.getInputStream());
              DataOutputStream output = new DataOutputStream(socket.getOutputStream());
              while (socket.isConnected() && !socket.isClosed()) {
                long size = input.readLong();
                if (renegotiate.compareAndSet(true, false)) {
                  ((SSLSocket) socket).startHandshake();
                }
                byte[] bytes = new byte[(int) size - 8];
                input.readFully(bytes);
                output.writeLong(size);
                output.write(bytes);
                output.flush();
              }
            } catch (IOException e) {
              // ignore, caused by client closed connection
            } finally {
              try {
                socket.close();
              } catch (IOException e) {
                exceptions.add(e);
              }
            }
          }
Test client to handle renegotiation from server
It only affects the next connection rather than all connections
After setting renegotiate to true, the next connection to the server will be renegotiated
ambry-network/src/test/java/com/github/ambry/network/EchoServer.java