private ByteBuffer safeAllocateByteBuffer(int size) {
        boolean error = true;
        try {
            ByteBuffer buffer = allocateByteBuffer(size);
            error = false;
            return buffer;
        } finally {
            if (error) {
                this.lock.lock();
                try {
                    this.nonPooledAvailableMemory += size;
                    if (!this.waiters.isEmpty())
                        this.waiters.peekFirst().signal();
                } finally {
                    this.lock.unlock();
                }
            }
        }
    }
Allocate a buffer.  If buffer allocation fails (e.g. because of OOM) then return the size count back to
available memory and signal the next waiter if it exists.
clients/src/main/java/org/apache/kafka/clients/producer/internals/BufferPool.java