Repository navigation
mon/MonClient: guard the pinger's MonConnection with the pinger's own lock - #71797
Conversation
… lock ping_monitor() is built to run without monc_lock. Its comment says so: it stands up a private messenger and a private MonClientPinger precisely so that a mon can be pinged while the MonClient is hunting or blocked waiting for auth to complete with another mon. 3e885ab added ceph_assert(ceph_mutex_is_locked_by_me(monc_lock)) to the MonConnection auth methods and passed MonClient's monc_lock to the MonConnection owned by the pinger. On the msgr2 handshake the messenger worker calls MonClientPinger::get_auth_request(), which forwards into MonConnection::get_auth_request(), where monc_lock is held by nobody and the assertion fires. The worker calls ceph_abort() and takes the process down, so librados' ping_monitor() aborts rather than returning; the python test dies with "Fatal Python error: Aborted" at test_ping_monitor. The ping path cannot satisfy that assertion as written, and taking monc_lock around the ping would not help: the callbacks run on a msgr worker thread, where is_locked_by_me() would still be false, and it would reintroduce the head-of-line blocking ping_monitor() exists to avoid. The assertion is worth keeping, since it guards the client authorizer. What was wrong is which lock the pinger's MonConnection was told to assert on. The pinger already has a lock for exactly this object, so use it, and take it in the four AuthClient overrides that reach into mc so the assertion is genuinely satisfied rather than side-stepped. No deadlock is introduced: wait_for_reply() releases the lock while waiting on the condvar, ms_dispatch() and ms_handle_reset() only set done and notify, and nothing under MonConnection's auth methods re-enters the pinger. MonConnection::start() does not assert and is unaffected. This is only observable in a build with CEPH_DEBUG_MUTEX, since ceph_mutex_is_locked_by_me() is otherwise defined to true, which is why it shows up in debug jobs. Fixes: https://tracker.ceph.com/issues/79732 Signed-off-by: Akshay Nazare <[email protected]>
The reference is no longer always MonClient's monc_lock: the pinger owns a MonConnection of its own and guards it with the pinger's lock, so the name is now misleading at the only place it is read, which is the assertion in each of the auth methods. Rename it to auth_lock, which says what it guards rather than who happens to own it. MonClient's own monc_lock and its assertions are untouched. No functional change. Signed-off-by: Akshay Nazare <[email protected]>
|
Thank you for your contribution. Since you are not yet a member of the Ceph organization with write permissions on ceph/ceph.git, our CI will not automatically run. Any member of the Ceph organization may label this PR |
tchaikov
left a comment
There was a problem hiding this comment.
lgtm.
but we still have a similar race: ping_monitor() sets pinger->mc and calls start() without pinger->lock, after connect_to_mon() has already started connecting, so a fast handshake can read mc unlocked. i think holding pinger->lock around those two is safe. mc is still null, start() only takes the connection's write_lock, and the worker calls the AuthClient hooks under AsyncConnection::lock, never write_lock.
The messenger is given the pinger as its auth client before the connection is made, so a msgr worker can call into MonClientPinger's AuthClient hooks as soon as connect_to_mon() starts the handshake. Those hooks dereference mc, which ping_monitor() was assigning afterwards without the lock: a fast handshake could therefore read mc while it was being assigned, or find it still null. Hold the pinger's lock from before connect_to_mon() until the MonConnection has been created and started, so a worker that gets there first waits for mc rather than racing with it. This cannot deadlock against the auth path. ProtocolV2 drops connection->lock around all four AuthClient calls, and DispatchQueue drops its own lock before delivering ms_dispatch() and ms_handle_reset(), so every thread that acquires the pinger's lock holds nothing else when it does. Only ping_monitor() takes the pinger's lock first and a messenger lock second. MPing is sent after the lock is dropped, since it does not touch mc. Signed-off-by: Akshay Nazare <[email protected]>
|
jenkins test make check |
|
This PR has been added to wip-bharath25-testing-20260918.001212-main. |
|
This is an automated message by src/script/redmine-upkeep.py. I have resolved the following tracker ticket due to the merge of this PR: No backports are pending for the ticket. If this is incorrect, please update the tracker |
Fixes: https://tracker.ceph.com/issues/79732
test_ping_monitoraborts the whole pytest process with SIGABRT instead of failing, so the run dies with "Fatal Python error: Aborted" attest_rados.py:118rather than reporting anything useful. It showed up in a crimson job, but it is not a crimson issue and not a test issue — it is a plain librados client bug.MonClient::ping_monitor()is deliberately built to run outsidemonc_lock. Its own comment says so: it stands up a private messenger and a privateMonClientPingerprecisely so a mon can be pinged while the MonClient is hunting, or blocked waiting for auth to complete with a different mon.3e885abc2aeaddedceph_assert(ceph_mutex_is_locked_by_me(monc_lock))to theMonConnectionauth methods, and passed MonClient'smonc_lockto theMonConnectionthat the pinger owns. On the msgr2 handshake the messenger worker callsMonClientPinger::get_auth_request(), which forwards intoMonConnection::get_auth_request(), wheremonc_lockis held by nobody. The assertion fires, the worker callsceph_abort(), and the process goes down.The ping path cannot satisfy that assertion as written. Taking
monc_lockaround the ping would not help either: the callbacks run on a msgr worker thread whereis_locked_by_me()would still be false, and it would reintroduce exactly the head-of-line blockingping_monitor()exists to avoid.The assertion is worth keeping, since it guards the client authorizer. What was wrong is which lock the pinger's
MonConnectionwas told to assert on. The pinger already has a lock for exactly this object, so this uses it, and takes it in the fourAuthClientoverrides that reach intomcso the assertion is genuinely satisfied rather than side-stepped.No deadlock is introduced:
wait_for_reply()releases the lock while waiting on the condvar,ms_dispatch()andms_handle_reset()only setdoneand notify, and nothing underMonConnection's auth methods re-enters the pinger.MonConnection::start()neither asserts nor reaches_init_auth(), soping_monitor()calling it unlocked is fine, and_init_auth()only asserts rather than locking, so calling through fromget_auth_request()does not self-deadlock.The second commit renames the
MonConnectionmember toauth_lock, since the reference is no longer always MonClient's lock and the old name is now misleading at the only places it is read. It is a pure rename, kept separate so it can be dropped if you would rather not have the churn.Verified locally
This only reproduces in a build with
CEPH_DEBUG_MUTEX, sinceceph_mutex_is_locked_by_me()is otherwise defined totrue— which is why it surfaces in debug jobs. Against a vstart cluster on such a build:MonClient:test_ping_monitordies withFatal Python error: Abortedattest_rados.py:118, exit 134 (SIGABRT) — the same signature as the tracker.test_ping_monitor PASSED, exit 0.MonClient.{cc,h}back and forth and relinking reproduces both outcomes reliably.test_rados.py: 90 passed. The one failure,test_ioctx_context_manager, is environmental — it needs anrbdpool that this vstart cluster does not create — and fails the same way without this change.Noticed nearby, not fixed here
MonClientPinger::wait_for_reply()setsdone = falseafterping_monitor()has already sent theMPing. A reply landing in that window setsdone = trueand is then clobbered, yielding a spuriousETIMEDOUT. The test only survives it because of itsif output is None: continueretry loop. That deserves its own patch.pinger->mc.reset()also destroys the connection without holding the lock, which is a pre-existing lifetime race now that the lock guardsmc. Locking it would mean holding the lock across~MonConnection'scon->mark_down(), and if that can dispatchms_handle_resetinline it would self-deadlock, so I left it alone rather than guess.Contribution Guidelines
To sign and title your commits, please refer to Submitting Patches to Ceph.
If you are submitting a fix for a stable branch (e.g. "quincy"), please refer to Submitting Patches to Ceph - Backports for the proper workflow.
When filling out the below checklist, you may click boxes directly in the GitHub web UI. When entering or editing the entire PR message in the GitHub web UI editor, you may also select a checklist item by adding an
xbetween the brackets:[x]. Spaces and capitalization matter when checking off items this way.Checklist