There is a potential deadlock due to synchronization used around both the producer.send() and in the produce callback in WorkerSourceTask. This can be triggered, for example, if:
1. WorkerSourceTask work thread is running sendRecords and therefore owns the lock on itself, then invokes producer.send() and needs a metadata update (sending to a new topic), which causes it to wait on the Metadata class, which is notified by the Sender thread when it has updated metadata.
2. Sender thread is processing a message completion, invokes the callback in WorkerSourceTask, which then tries to invoke recordSent, which needs to acquire the WorkerSourceTask lock. It will wait on this lock and never process the metadata update request, so the other thread will never proceed either.