You have tried to open a file which you have previously closed with lock.
Recode your program to avoid opening a file which has previously been closed with lock.