private void testIOExceptionsDuringHandshake(Args args,
                                                 FailureAction readFailureAction,
                                                 FailureAction flushFailureAction) throws Exception {
        TestSslChannelBuilder channelBuilder = new TestSslChannelBuilder(ConnectionMode.CLIENT);
        boolean done = false;
        for (int i = 1; i <= 100; i++) {
            String node = String.valueOf(i);

            channelBuilder.readFailureAction = readFailureAction;
            channelBuilder.flushFailureAction = flushFailureAction;
            channelBuilder.failureIndex = i;
            channelBuilder.configure(args.sslClientConfigs);
            this.selector = new Selector(10000, new Metrics(), TIME, "MetricGroup", channelBuilder, new LogContext());

            InetSocketAddress addr = new InetSocketAddress("localhost", server.port());
            selector.connect(node, addr, BUFFER_SIZE, BUFFER_SIZE);
            for (int j = 0; j < 30; j++) {
                selector.poll(1000L);
                KafkaChannel channel = selector.channel(node);
                if (channel != null && channel.ready()) {
                    done = true;
                    break;
                }
                if (selector.disconnected().containsKey(node)) {
                    ChannelState.State state = selector.disconnected().get(node).state();
                    assertTrue(state == ChannelState.State.AUTHENTICATE || state == ChannelState.State.READY,
                        "Unexpected channel state " + state);
                    break;
                }
            }
            KafkaChannel channel = selector.channel(node);
            if (channel != null)
                assertTrue(channel.ready(), "Channel not ready or disconnected:" + channel.state().state());
            selector.close();
        }
        assertTrue(done, "Too many invocations of read/write during SslTransportLayer.handshake()");
    }
Tests that if the remote end closes the connection during SSL handshake while writing data,
the disconnection is not treated as an authentication failure.
clients/src/test/java/org/apache/kafka/common/network/SslTransportLayerTest.java