moved resource lock to the right place for APIConnection