Fixed potential deadlock while opening file.