Skip to content

mon/MonClient: guard the pinger's MonConnection with the pinger's own lock - #71797

Merged
SrinivasaBharath merged 3 commits into
ceph:mainfrom
akkki007:wip-79732-ping-monitor-monc-lock
Sep 30, 2026
Merged

SrinivasaBharath merged 3 commits into
ceph:mainfrom
akkki007:wip-79732-ping-monitor-monc-lock

Conversation

@akkki007

@akkki007 akkki007 commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

Fixes: https://tracker.ceph.com/issues/79732

test_ping_monitor aborts the whole pytest process with SIGABRT instead of failing, so the run dies with "Fatal Python error: Aborted" at test_rados.py:118 rather 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 outside monc_lock. Its own comment says so: it stands up a private messenger and a private MonClientPinger precisely so a mon can be pinged while the MonClient is hunting, or blocked waiting for auth to complete with a different mon.

3e885abc2ae 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 that the pinger owns. 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. The assertion fires, the worker calls ceph_abort(), and the process goes down.

The ping path cannot satisfy that assertion as written. Taking monc_lock around the ping would not help either: the callbacks run on a msgr worker thread where is_locked_by_me() would still be false, and it would reintroduce exactly 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 this uses it, and takes 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() neither asserts nor reaches _init_auth(), so ping_monitor() calling it unlocked is fine, and _init_auth() only asserts rather than locking, so calling through from get_auth_request() does not self-deadlock.

The second commit renames the MonConnection member to auth_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, since ceph_mutex_is_locked_by_me() is otherwise defined to true — which is why it surfaces in debug jobs. Against a vstart cluster on such a build:

  • stock MonClient: test_ping_monitor dies with Fatal Python error: Aborted at test_rados.py:118, exit 134 (SIGABRT) — the same signature as the tracker.
  • with this change: test_ping_monitor PASSED, exit 0.
  • flipping only MonClient.{cc,h} back and forth and relinking reproduces both outcomes reliably.
  • the rest of test_rados.py: 90 passed. The one failure, test_ioctx_context_manager, is environmental — it needs an rbd pool that this vstart cluster does not create — and fails the same way without this change.

Noticed nearby, not fixed here

MonClientPinger::wait_for_reply() sets done = false after ping_monitor() has already sent the MPing. A reply landing in that window sets done = true and is then clobbered, yielding a spurious ETIMEDOUT. The test only survives it because of its if output is None: continue retry 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 guards mc. Locking it would mean holding the lock across ~MonConnection's con->mark_down(), and if that can dispatch ms_handle_reset inline 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 x between the brackets: [x]. Spaces and capitalization matter when checking off items this way.

Checklist

  • Tracker (select at least one)
    • References tracker ticket
    • Very recent bug; references commit where it was introduced
    • New feature (ticket optional)
    • Doc update (no ticket needed)
    • Code cleanup (no ticket needed)
  • Component impact
    • Affects Dashboard, opened tracker ticket
    • Affects Orchestrator, opened tracker ticket
    • No impact that needs to be tracked
  • Documentation (select at least one)
    • Updates relevant documentation
    • No doc update is appropriate
  • Tests (select at least one)

… 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]>
@akkki007
akkki007 requested a review from a team as a code owner September 15, 2026 09:23
@github-actions

Copy link
Copy Markdown

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 ci-approved to allow Jenkins CI jobs to run.

@tchaikov tchaikov left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@tchaikov
tchaikov requested a review from batrick September 15, 2026 11:19
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]>
@batrick

batrick commented Sep 17, 2026

Copy link
Copy Markdown
Member

jenkins test make check

@batrick batrick left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense to me!

@SrinivasaBharath

Copy link
Copy Markdown
Contributor

This PR has been added to wip-bharath25-testing-20260918.001212-main.

@ronen-fr

Copy link
Copy Markdown
Contributor

@SrinivasaBharath
SrinivasaBharath merged commit afc052c into ceph:main Sep 30, 2026
17 checks passed
@github-actions

Copy link
Copy Markdown

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
ticket and reset to Pending Backport state.

Update Log: https://github.com/ceph/ceph/actions/runs/36648871529

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants