Correct lock/unlock for the query busy code