private void doClose(KafkaChannel channel, boolean notifyDisconnect) {
        SelectionKey key = channel.selectionKey();
        try {
            immediatelyConnectedKeys.remove(key);
            keysWithBufferedRead.remove(key);
            channel.close();
        } catch (IOException e) {
            log.error("Exception closing connection to node {}:", channel.id(), e);
        } finally {
            key.cancel();
            key.attach(null);
        }

        this.sensors.connectionClosed.record();
        this.explicitlyMutedChannels.remove(channel);
        if (notifyDisconnect)
            this.disconnected.put(channel.id(), channel.state());
    }
Begin closing this connection.
If 'closeMode' is `CloseMode.GRACEFUL`, the channel is disconnected here, but outstanding receives
are processed. The channel is closed when there are no outstanding receives or if a send is
requested. For other values of `closeMode`, outstanding receives are discarded and the channel
is closed immediately.

The channel will be added to disconnect list when it is actually closed if `closeMode.notifyDisconnect`
is true.
clients/src/main/java/org/apache/kafka/common/network/Selector.java