Fix possible race condition where queue buffer array length was retrieved outside the lock