improve file lock handling for errors