public void initiateClose() {
        // Ensure accumulator is closed first to guarantee that no more appends are accepted after
        // breaking from the sender loop. Otherwise, we may miss some callbacks when shutting down.
        this.accumulator.close();
        this.running = false;
        this.wakeup();
    }
Start closing the sender (won't actually complete until all data is sent out)
clients/src/main/java/org/apache/kafka/clients/producer/internals/Sender.java