Skip to content

librados: optionally retry the mon handshake on transient connect failure - #69318

Open
lumir-sliva wants to merge 4 commits into
ceph:mainfrom
lumir-sliva:mgr-rados-connect-retry
Open

lumir-sliva wants to merge 4 commits into
ceph:mainfrom
lumir-sliva:mgr-rados-connect-retry

Conversation

@lumir-sliva

@lumir-sliva lumir-sliva commented Jun 7, 2026 •

Copy link
Copy Markdown
Contributor

Description

A librados client that opens its handle while the monitors are (re)forming
quorum can hit a transient failure during connect(), for example a cephx
EPERM from a monitor that is mid-election, and fail even though the condition
clears moments later. connect() contacts the mons twice (the monmap/config
bootstrap and authentication) and either can be affected.

The motivating case is a mgr always-on module (volumes, rbd_support) that
opens the shared librados handle during construction right after a mgr
failover. The mgr does not retry a module that throws in __init__, so a
single transient failure drops the module and the cluster sits in HEALTH_ERR
("Module 'X' has failed: Not found or unloadable") until an operator runs
ceph mgr fail, long after the condition cleared. Seen on a production
cluster after a mon election.

Fix

Four commits, each standing on its own:

mon/MonClient: start a fresh hunt when authenticate() is retried.
authenticate() gives up in two ways. When the monitors reject the client the
last pending connection is erased before the error is recorded, so a later
call hunts again. When it times out instead, the connections are still hunting
and authenticate_err still holds the timeout, so a later call finds
_opened() true, skips the reopen and returns the previous call's error
without contacting a monitor. It now reopens the session whenever a previous
attempt left an error behind.

librados: leave CONNECTING behind when connect() fails at the
bootstrap.
Every failure path clears the state through the out: label
except the bootstrap early return, so a handle whose connect failed there
returned -EINPROGRESS on every later attempt. Pre-existing, and a
prerequisite for retrying at all.

librados: the retry itself. A bounded, opt-in retry around both
mon-contact steps in RadosClient::connect(), controlled by two new options:

  • rados_connect_retries (default 0)
  • rados_connect_retry_interval (default 1.0s, linear backoff)

The default of 0 keeps the current fail-immediately behaviour for every
existing librados caller. Since the retry lives in the C++ connect path it
covers both the C (rados_connect) and C++ APIs. This replaces the earlier
mgr-only Python retry, per @NitzanMordhai's review, so any client started
during an election window benefits.

mgr: opt in. ceph-mgr defaults rados_connect_retries to 5 through its
global_init defaults map. Being a default it is scoped to the mgr process
and an operator can still set the option to 0; setting it from the module
would instead rewrite the config shared by the whole mgr. The handle is also
kept out of the property cache until connect() succeeds, so a failed connect
no longer leaves a dead instance behind.

The retries are bounded twice, by rados_connect_retries and by
client_mount_timeout of wall-clock time per step. An attempt that has
already spent that long hunting for unreachable monitors is not repeated, so a
connect() against unreachable monitors gives up after about the same time as
before. The retries only add time while the monitors are reachable but
rejecting the client, where every attempt fails within milliseconds and the
whole budget is the backoff, 15s at the mgr default.

Testing

  • unittest_monclient_retry (new): authenticates twice against a socket that
    accepts connections but never answers, and checks the second call waits out
    its own timeout instead of returning the first call's error. Returns in
    about 9us without the MonClient change, 0.5s with it.
  • unittest_librados: the default of 0 does not retry, retries are bounded
    and back off linearly, retries stop once client_mount_timeout has elapsed
    even when the count would allow more, and a handle stays usable after a
    failed connect (the last one fails without the state fix).
  • 5 mgr unit tests, including one asserting the module never writes to the
    shared config.
  • Validated on vstart: a forced mid-hunt timeout on the first attempt is
    recovered by the retry, while the old code burned all three retries in
    microseconds against a healthy monitor and failed the connect. Also checked
    the mgr reports 5 while mons and plain clients report 0, and that
    ceph config set mgr rados_connect_retries 0 wins over the default.

Tracker: https://tracker.ceph.com/issues/77151

Checklist

  • Tracker (select at least one)
    • References tracker ticket
  • Component impact
    • No impact that needs to be tracked
  • Documentation (select at least one)
    • Updates relevant documentation
  • Tests (select at least one)
    • Includes unit test(s)

@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run.

16 similar comments
@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run.

@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run.

@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run.

@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run.

@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run.

@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run.

@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run.

@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run.

@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run.

@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run.

@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run.

@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run.

@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run.

@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run.

@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run.

@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run.

@lumir-sliva

Copy link
Copy Markdown
Contributor Author

@batrick mind taking a look when you get a chance? Adds a bounded retry around the librados connect during mgr module construction (fresh handle per attempt, caches only on success), so a transient EPERM during a mon election doesn't leave an always-on module stuck in HEALTH_ERR until a manual mgr fail. Hit this on a squid prod cluster. 3 unit tests + real-librados vstart validation.

@NitzanMordhai

Copy link
Copy Markdown
Contributor

@lumir-sliva i'm thinking loud here - maybe its better to move the retry into RadosClient::connect or lower level of connect so we will have the same behaive for the c and c++ api calls.

@lumir-sliva

Copy link
Copy Markdown
Contributor Author

@lumir-sliva i'm thinking loud here - maybe its better to move the retry into RadosClient::connect or lower level of connect so we will have the same behaive for the c and c++ api calls.

I agree, I'll look into it later today.

@github-actions

Copy link
Copy Markdown

Config Diff Tool Output

+ added: rados_connect_retry_interval (global.yaml.in)
+ added: rados_connect_retries (global.yaml.in)

The above configuration changes are found in the PR. Please update the relevant release documentation if necessary.
Ignore this comment if docs are already updated. To make the "Check ceph config changes" CI check pass, please comment /config check ok and re-run the test.

@lumir-sliva lumir-sliva changed the title mgr/mgr_module: retry transient rados connect during module construction librados: optionally retry the mon handshake on transient connect failure Jul 23, 2026
@lumir-sliva

Copy link
Copy Markdown
Contributor Author

/config check ok

@NitzanMordhai NitzanMordhai 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.

@lumir-sliva thank you for addressing my previous comment! i have few more thoughts on that changes

Comment thread src/pybind/mgr/mgr_module.py Outdated
# override the shipped default of 0; if an operator has raised
# rados_connect_retries via config, keep their value.
if rados_inst.conf_get('rados_connect_retries') == '0':
rados_inst.conf_set('rados_connect_retries', '5')

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.

That one will affect globally - that means that if the user doesn't want any retry, it will force a retry on the other modules as well

Comment on lines +320 to +323
err = with_retries("authentication", [&] {
return monclient.authenticate(std::chrono::duration<double>(
conf.get_val<std::chrono::seconds>("client_mount_timeout")).count());
});

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.

Unlike the previous retry, you are reusing the monclient instance - the connections under pending_connections are still retrying while you reauthenticate the monclient, which causes you to get the same results

Comment thread src/librados/RadosClient.cc Outdated
}
return mc_bootstrap.get_monmap_and_config();
});
if (err < 0)

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.

This is pre-exist bug, but now with the retry, it should be fixed - the state is still in CONNECTING state - we need to change it here when we are about to give up

Comment thread src/pybind/mgr/tests/test_mgr_module.py Outdated
import mgr_module


def _make_handle(connect_side_effect=None, retries='0'):

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.

Can we maybe add some more tests for the connection part for the c++ side?
I think we are missing the retry test entirely

authenticate() gives up in two different ways. When the monitors actively
reject the client, the last pending connection is erased before the error is
recorded, so nothing is left open and a later call hunts again. When it times
out instead, the pending connections are still hunting and authenticate_err
still holds the timeout, so a later call finds _opened() true, skips the
reopen and falls straight out of the wait loop with the error the previous
call recorded. The monitors are never contacted again and the caller is handed
a stale answer immediately.

Reopen the session whenever a previous attempt left an error behind, not only
when nothing is open, so that a caller asking to authenticate again really
does get another attempt.

The test authenticates twice against a socket that accepts connections but
never answers, and checks that the second call waits for its timeout instead
of returning at once with what the first call recorded.

Tracker: https://tracker.ceph.com/issues/77151
Signed-off-by: Lumir Sliva <[email protected]>
connect() marks the handle CONNECTING up front, and every failure path clears
it again through the out: label except the monmap/config bootstrap, which
returns directly. A handle whose connect() failed there is left believing a
connect is still in flight, so every later attempt on it returns -EINPROGRESS
rather than trying again.

Set the state back to DISCONNECTED on that path too, and cover it with a test
that connects twice through a handle pointed at a monmap file that does not
exist.

Tracker: https://tracker.ceph.com/issues/77151
Signed-off-by: Lumir Sliva <[email protected]>
@lumir-sliva

Copy link
Copy Markdown
Contributor Author

Reworked all four, and split the series into four commits so each piece stands on its own.

That one will affect globally - that means that if the user doesn't want any retry, it will force a retry on the other modules as well

Right. The handle shares the mgr's CephContext, so conf_set was rewriting the config for the whole process, and the == '0' guard couldn't tell the shipped default from an operator who explicitly wants 0.

Dropped it. rados_connect_retries is now an alternate default in ceph-mgr's global_init defaults map, next to the existing keyring one. It applies to the mgr process only, and since it goes in at CONF_DEFAULT anything from the config file or the mon config db still wins, including an explicit 0. Checked on vstart: mgr reports 5, mon and plain clients report 0, and ceph config set mgr rados_connect_retries 0 takes effect. test_rados_leaves_the_shared_config_alone asserts the module never calls conf_set again.

Unlike the previous retry, you are reusing the monclient instance - the connections under pending_connections are still retrying while you reauthenticate the monclient, which causes you to get the same results

Good catch, this was real. It splits by how authenticate() gave up:

  • EPERM from the mons: handle_auth erases the last pending connection before recording the error, so pending_cons is empty, _opened() is false, and the retry did hunt again. That's the path I had validated, which is why I missed the other one.
  • Timeout: authenticate_err is set by the waiter while the connections are still hunting, so _opened() is true, the retry skips _reopen_session() and falls straight out of the wait loop with the error the previous call recorded. The monitors are never contacted again.

MonClient::authenticate() now reopens the session whenever a previous attempt left an error behind, not only when nothing is open. Measured against a healthy vstart mon with a mid-hunt timeout forced on the first attempt: before, all three retries returned in microseconds and connect failed; after, the retry re-hunts and connect succeeds. 3/3 runs each way.

This is pre-exist bug, but now with the retry, it should be fixed - the state is still in CONNECTING state

Fixed, in its own commit. Every other failure path goes out through out: which resets the state, the bootstrap early return didn't, so a handle whose first connect failed there returned -EINPROGRESS forever after.

Can we maybe add some more tests for the connection part for the c++ side? I think we are missing the retry test entirely

Added, all under make check:

  • src/test/librados/librados.cc: the default of 0 does not retry, retries are bounded and back off linearly, and a handle stays usable after a failed connect. The last one fails without the state fix.
  • src/test/mon/test_monclient_retry.cc: authenticates twice against a socket that accepts connections but never answers, so the first call times out mid-hunt. The second call has to wait out its own timeout instead of handing back the first call's error. Without the MonClient change it returns in about 9us rather than 0.5s.

One tradeoff worth naming: retries are only cheap while the monitors actively reject. If they are unreachable instead, an attempt blocks for client_mount_timeout, so the mgr default of 5 stretches the worst case for module construction. I think that is the better failure mode, since today the module is dropped and stays dead until someone runs ceph mgr fail, and the mgr has nothing to do without mons anyway, but happy to lower the default if you would rather bound it.

@lumir-sliva

Copy link
Copy Markdown
Contributor Author

/config check ok

@lumir-sliva

Copy link
Copy Markdown
Contributor Author

@NitzanMordhai mind having a look when you get a chance please?

@NitzanMordhai NitzanMordhai 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.

@lumir-sliva looks good, just make sure you are reading my last comment, to be sure this is what we really want.

}
};

err = with_retries("monmap/config bootstrap", [&] {

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.

@lumir-sliva just to be sure we are clear about that - rados_connect_retries = 5 that means 6 retries. in get_monmap_and_config() we have 10 retries as well. client_mount_timeout default is 300s -> we have at most 610300 = 5 hours. (vs 50 min today for the most worst case scenario )

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

rados_connect_retries = 5 that means 6 retries. in get_monmap_and_config() we have 10 retries as well. client_mount_timeout default is 300s -> we have at most 610300 = 5 hours.

6 attempts per step, yes. The 10 tries in get_monmap_and_config() don't multiply client_mount_timeout though: a failed or timed-out authenticate() hits if (r < 0) break; (MonClient.cc:164) and the loop is done. It only goes around again when auth succeeded but the config never arrived, and each of those rounds waits one mon_client_hunt_interval (3s). So the numbers were 30 min for the bootstrap and 60 min for the whole connect() in the worst case, against 5 and 10 today.

Still too much, and you're right that the count alone is the wrong bound when the monitors are unreachable. Pushed a change so the retries are also bounded by client_mount_timeout of wall-clock time per step: an attempt that already spent that long hunting isn't repeated, so connect() against unreachable monitors gives up after about the same time it always has. The retries only add time while the monitors are reachable but rejecting, where every attempt fails in milliseconds and the whole budget is the 15s of backoff at the mgr default. Reused the existing option rather than adding a third one.

New unittest_librados case sets 1000 retries with a 1s client_mount_timeout and checks the connect gives up in about a second; it runs for minutes without the bound. Would appreciate one more look at that delta since it landed after your approval.

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.

Right, looks good! thanks

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the reviews as well Nitzan, can you give ok-to-test and set the flag for need-qa please? Im just a contributor so I don't have the powers.

…lure

A client that opens a librados handle while the monitors are mid-election can
get a transient cephx EPERM and fail to connect, even though the condition
clears moments later. connect() contacts the mons twice, in the monmap/config
bootstrap and in authentication, and either can hit this.

This is how a mgr always-on module that opens the shared librados handle
during construction (volumes via VolumeClient, or rbd_support) right after a
mgr failover ends up permanently failed. The mgr does not retry a module that
throws in __init__, so the module is dropped and the cluster reports
HEALTH_ERR ("Module 'X' has failed: Not found or unloadable") until an
operator runs `ceph mgr fail`, long after the condition cleared. This was seen
on a production cluster after a mon election.

Add a bounded, opt-in retry around both mon-contact steps in
RadosClient::connect(). Each step is safe to reattempt: the bootstrap runs on
a throwaway MonClient, and authenticate() drops whatever a failed attempt left
behind and hunts the monitors again. Two new options control it,
rados_connect_retries (default 0) and rados_connect_retry_interval (default
1.0s, linear backoff). The default of 0 preserves the historical
fail-immediately behaviour for every existing caller, and because the retry
lives in the C++ connect path it covers both the C and the C++ rados APIs.

The retries are also bounded by client_mount_timeout of wall-clock time per
step. An attempt that has already spent that long hunting for unreachable
monitors is not repeated, so connect() against unreachable monitors gives up
after about the same time it always has. The retries only add time while the
monitors are reachable but rejecting the client, where every attempt fails
within milliseconds and the whole budget is the backoff.

Tracker: https://tracker.ceph.com/issues/77151
Signed-off-by: Lumir Sliva <[email protected]>
A module opens its librados handle while the mgr is coming up, which is
exactly when the monitors may still be (re)forming quorum. A module that
throws out of __init__ is never reconstructed, so a connect that fails in that
window leaves the module dropped and the cluster in HEALTH_ERR until an
operator runs `ceph mgr fail`.

Default rados_connect_retries to 5 for ceph-mgr so connect() can ride out a
transient failure. Being a default it applies to the mgr process alone, and an
operator who wants the historical fail-immediately behaviour can still set the
option to 0. Setting the option from the module instead would write to the
config the whole mgr shares and would override whatever the operator chose.

Also keep the handle out of the property cache until connect() has actually
succeeded, so a module that catches the error and asks for the handle again
gets a fresh attempt rather than a dead instance.

Tracker: https://tracker.ceph.com/issues/77151
Signed-off-by: Lumir Sliva <[email protected]>
@lumir-sliva

Copy link
Copy Markdown
Contributor Author

/config check ok

@SrinivasaBharath

Copy link
Copy Markdown
Contributor

This PR has been added to wip-bharath24-testing-20260918.001059-main.

@SrinivasaBharath

Copy link
Copy Markdown
Contributor

@lumir-sliva - Please resolve the PR checks and proceed with merging the PR once all checks have passed. If a rerun is required, remove the "Tested" label and add the "needs-qa" label.

@lumir-sliva

Copy link
Copy Markdown
Contributor Author

@NitzanMordhai could you please add the labels? I'm not part of the org

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.

4 participants