efsw
efsw copied to clipboard
[WIP]fix invalid watcher iterator while found before removing it from map …
{
{
Lock lock( mWatchesLock);
wit = mWatches.find( pevent->wd);
}
wit->second;
}
iterator wit
might be an invalid if this iterator has been removed from map collection after find
method.
I found it fix invalid iterator issue but there is another deadlock condition:
- run & while function holds mWatcherLock, then handleAction wants minitLock
- removeWatcher function hodls mInitLock, but requires mWatcherLock
Hi @ashione, thanks for collaborating! I think this can generate a deadlock as you mentioned, let me check it a little bit. Maybe we can get the iterator end inside the lock, something like:
bool foundIt = false;
{
Lock lock( mWatchesLock );
wit = mWatches.find( pevent->wd );
foundIt = wit != mWatches.end();
}
if ( foundIt ) {
Hi @ashione, thanks for collaborating! I think this can generate a deadlock as you mentioned, let me check it a little bit. Maybe we can get the iterator end inside the lock, something like:
bool foundIt = false; { Lock lock( mWatchesLock ); wit = mWatches.find( pevent->wd ); foundIt = wit != mWatches.end(); } if ( foundIt ) {
Actually, we use this data in handleAction
after iterator located but related inotify pointer had been deleted.
How to avoid accessing invalid iterator out of thie scope lock domain?