If there is lock contention while multiple threads check if a delayed operation may be completed (e.g. a produce request with acks=-1), only the thread that acquires the lock without blocking attempts to complete the operation. This change was made to avoid deadlocks under
KAFKA-5970. But this leaves a timing window when an operation becomes ready to complete after another thread has acquired the lock and performed the check for completion, but not yet released the lock. In this case, the operation may never be completed and will timeout unless there are other operations with the same key. The timeout was observed in a failed system test where a produce request timed out, causing the test failure.