From: Jason Dillaman Date: Wed, 5 Aug 2020 16:36:26 +0000 (-0400) Subject: test/rbd-mirror: pool watcher registration error might result in race X-Git-Tag: v15.2.9~122^2~89^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=c88afe83e4dbf6f817d45a9e52fd67aa2b918401;p=ceph.git test/rbd-mirror: pool watcher registration error might result in race The init finish context should be swapped out before it attempts to re-register the watcher. This affects the test case which mocks the timer to fire immediately instead of after 30 seconds. Fixes: https://tracker.ceph.com/issues/46669 Signed-off-by: Jason Dillaman (cherry picked from commit c89d31ebf6c412d609123979c63ebc600b70e179) --- diff --git a/src/tools/rbd_mirror/PoolWatcher.cc b/src/tools/rbd_mirror/PoolWatcher.cc index 359ca95d5377..6d8a8fc04155 100644 --- a/src/tools/rbd_mirror/PoolWatcher.cc +++ b/src/tools/rbd_mirror/PoolWatcher.cc @@ -178,10 +178,12 @@ void PoolWatcher::handle_register_watcher(int r) { std::swap(on_init_finish, m_on_init_finish); } else if (r == -ENOENT) { dout(5) << "mirroring directory does not exist" << dendl; - schedule_refresh_images(30); + { + std::lock_guard locker{m_lock}; + std::swap(on_init_finish, m_on_init_finish); + } - std::lock_guard locker{m_lock}; - std::swap(on_init_finish, m_on_init_finish); + schedule_refresh_images(30); } else { derr << "unexpected error registering mirroring directory watch: " << cpp_strerror(r) << dendl;