MODE-2277-3.x Ported MODE-2277 from master

This PR contains an additional significant commit, which changes the multi-threaded code in `RepositoryChangeBus` to avoid deadlocking when a listener attempts to unregister itself.