Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP]fix invalid watcher iterator while found before removing it from map … #154

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ashione
Copy link

@ashione ashione commented Mar 6, 2023

{
{
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.

@ashione
Copy link
Author

ashione commented Mar 6, 2023

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

@SpartanJ SpartanJ self-assigned this Mar 6, 2023
@SpartanJ
Copy link
Owner

SpartanJ commented Mar 6, 2023

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 ) {

@ashione
Copy link
Author

ashione commented Mar 6, 2023

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?

@ashione ashione changed the title fix invalid watcher iterator while found before removing it from map … [WIP]fix invalid watcher iterator while found before removing it from map … Mar 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants