Skip to content

[xcode11.1] [Foundation] Remove a possible race condition when interacting with the notification centre. - #7184

Merged
dalexsoto merged 3 commits into
dotnet:xcode11.1from
monojenkins:backport-pr-6537-to-xcode11.1
Oct 7, 2019
Merged

dalexsoto merged 3 commits into
dotnet:xcode11.1from
monojenkins:backport-pr-6537-to-xcode11.1

Conversation

@monojenkins

Copy link
Copy Markdown
Contributor

Although it looked that it was not possible, due to the fact that the
RemoveObserversFromList does lock on the list of observers, we have
threads that are stepping on each other when the list is cleaned up.
Adding a lock around the AddObserver and RemoveObserver will ensure that
the handler does not call the removal more than once with an object that
was already removed.

Fixes #6387

Backport of #6537.

/cc @mandel-macaque

…the notification centre.

Although it looked that it was not possible, due to the fact that the
RemoveObserversFromList oes lock on the list of observers, we have
threads that are stepping on each other when the list is cleaned up.
Adding a lock around the AddObserver and RemoveObserver will ensure that
the handler does not call the removal more than once with an object that
was already removed.

Fixes dotnet#6387
@monojenkins monojenkins added this to the xcode11.1 milestone Oct 7, 2019
@monojenkins

Copy link
Copy Markdown
Contributor Author

Build success
✅ Build succeeded
⚠️ Mono built from source
✅ API Diff (from stable)
✅ API Diff (from PR only) (no change)
✅ Generator Diff (no change)
✅ Test run succeeded

@dalexsoto
dalexsoto merged commit e2963d9 into dotnet:xcode11.1 Oct 7, 2019
VincentDondain pushed a commit to VincentDondain/xamarin-macios that referenced this pull request Oct 16, 2019
…cting with the notification centre. (dotnet#7184)

* [Foundation] Remove a possible race condition when intereacting with the notification centre.

Although it looked that it was not possible, due to the fact that the
RemoveObserversFromList oes lock on the list of observers, we have
threads that are stepping on each other when the list is cleaned up.
Adding a lock around the AddObserver and RemoveObserver will ensure that
the handler does not call the removal more than once with an object that
was already removed.

Fixes dotnet#6387

* Move the removal of the notification to inside the lock in the dispose method.

* Better locking as per reviews.
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.

5 participants