fix lock wait timeout and deadlock