Repository navigation
librados: optionally retry the mon handshake on transient connect failure - #69318
lumir-sliva wants to merge 4 commits into
Conversation
|
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
|
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. |
|
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. |
|
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. |
|
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. |
|
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. |
|
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. |
|
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. |
|
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. |
|
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. |
|
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. |
|
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. |
|
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. |
|
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. |
|
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. |
|
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. |
|
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. |
|
@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. |
|
@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. |
b4126cc to
ab50fbb
Compare
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. |
|
/config check ok |
NitzanMordhai
left a comment
There was a problem hiding this comment.
@lumir-sliva thank you for addressing my previous comment! i have few more thoughts on that changes
| # 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') |
There was a problem hiding this comment.
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
| err = with_retries("authentication", [&] { | ||
| return monclient.authenticate(std::chrono::duration<double>( | ||
| conf.get_val<std::chrono::seconds>("client_mount_timeout")).count()); | ||
| }); |
There was a problem hiding this comment.
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
| } | ||
| return mc_bootstrap.get_monmap_and_config(); | ||
| }); | ||
| if (err < 0) |
There was a problem hiding this comment.
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
| import mgr_module | ||
|
|
||
|
|
||
| def _make_handle(connect_side_effect=None, retries='0'): |
There was a problem hiding this comment.
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]>
ab50fbb to
7a515e2
Compare
|
Reworked all four, and split the series into four commits so each piece stands on its own.
Right. The handle shares the mgr's CephContext, so Dropped it.
Good catch, this was real. It splits by how authenticate() gave up:
Fixed, in its own commit. Every other failure path goes out through
Added, all under make check:
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 |
|
/config check ok |
|
@NitzanMordhai mind having a look when you get a chance please? |
NitzanMordhai
left a comment
There was a problem hiding this comment.
@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", [&] { |
There was a problem hiding this comment.
@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 )
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Right, looks good! thanks
There was a problem hiding this comment.
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]>
7a515e2 to
8e55102
Compare
|
/config check ok |
|
This PR has been added to wip-bharath24-testing-20260918.001059-main. |
|
@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. |
|
@NitzanMordhai could you please add the labels? I'm not part of the org |
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 cephxEPERM from a monitor that is mid-election, and fail even though the condition
clears moments later.
connect()contacts the mons twice (the monmap/configbootstrap and authentication) and either can be affected.
The motivating case is a mgr always-on module (
volumes,rbd_support) thatopens the shared librados handle during construction right after a mgr
failover. The mgr does not retry a module that throws in
__init__, so asingle 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 productioncluster after a mon election.
Fix
Four commits, each standing on its own:
mon/MonClient: start a fresh hunt whenauthenticate()is retried.authenticate()gives up in two ways. When the monitors reject the client thelast 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_errstill holds the timeout, so a later call finds_opened()true, skips the reopen and returns the previous call's errorwithout contacting a monitor. It now reopens the session whenever a previous
attempt left an error behind.
librados: leave CONNECTING behind whenconnect()fails at thebootstrap. Every failure path clears the state through the
out:labelexcept the bootstrap early return, so a handle whose connect failed there
returned
-EINPROGRESSon every later attempt. Pre-existing, and aprerequisite for retrying at all.
librados: the retry itself. A bounded, opt-in retry around bothmon-contact steps in
RadosClient::connect(), controlled by two new options:rados_connect_retries(default0)rados_connect_retry_interval(default1.0s, linear backoff)The default of
0keeps the current fail-immediately behaviour for everyexisting librados caller. Since the retry lives in the C++ connect path it
covers both the C (
rados_connect) and C++ APIs. This replaces the earliermgr-only Python retry, per @NitzanMordhai's review, so any client started
during an election window benefits.
mgr: opt in. ceph-mgr defaultsrados_connect_retriesto 5 through itsglobal_initdefaults map. Being a default it is scoped to the mgr processand 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 connectno longer leaves a dead instance behind.
The retries are bounded twice, by
rados_connect_retriesand byclient_mount_timeoutof wall-clock time per step. An attempt that hasalready spent that long hunting for unreachable monitors is not repeated, so a
connect()against unreachable monitors gives up after about the same time asbefore. 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 thataccepts 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
MonClientchange, 0.5s with it.unittest_librados: the default of 0 does not retry, retries are boundedand back off linearly, retries stop once
client_mount_timeouthas elapsedeven when the count would allow more, and a handle stays usable after a
failed connect (the last one fails without the state fix).
shared config.
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 0wins over the default.Tracker: https://tracker.ceph.com/issues/77151
Checklist