Grr, the “theuni requested changes” is a bit overstated… There are a few fixes here and I can’t produce any real-world issues, so utACK from me for 0.16 for the sake of not dragging it out.
Further discussion for master, or 0.16 if you still feel like messing with it:
Strange, your tests results (RAII behavior) don’t line up with what I see from the docs/code. I’ll play with tests.
You mentioned:
The FILE* file = fsbridge::fopen(pathLockFile, "a");
wipes the ‘we own this lock’ administration
And from the Boost docs:
In POSIX, when two file descriptors are used to lock a file if a descriptor is closed, all file locks set by the calling process are cleared.
Is it possible that it was the fclose rather than the fopen? Because that would explain everything neatly, I think. In the probe_only
case, You create a lock, lock it, then destroy it. Then on the next invocation you fopen/fclose it, which basically gives a clean start before you create a new lock, lock again, etc.
To be clear, my concern is that in the near future we might adapt LockDirectory() and add UnlockDirectory() for some feature like multi-wallet-dirs, only to be hit with a hard-to-diagnose bug when UnlockDirectory() quietly doesnt’ work as intended.
The boost docs suggest using RAII generics here:
scoped_lock and sharable_lock can be used to make file locking easier in the presence of exceptions, just like with mutexes.
And file_lock’s destructor is pretty straightforward, I don’t see how it could be doing any unlocking:
0// m_file_hnd: typedef int (void* for win)
1// ipcdetail::close_file: ::close (CloseHandle() for win)
2inline file_lock::~file_lock()
3{
4 if(m_file_hnd != ipcdetail::invalid_file()){
5 ipcdetail::close_file(m_file_hnd);
6 m_file_hnd = ipcdetail::invalid_file();
7 }
8}