remove several race conditions around lock file by opening it once