I moved the flag config within the try block so that it's covered by the file access lock and doesn't throw IO exceptions.