Skip to content

[DNM] ProtocolV2: make handle_existing_connection check for cookie mismatch first - #63413

Merged
yuriw merged 5 commits into
ceph:mainfrom
kamoltat:wip-ksirivad-fix-71344
Jun 19, 2025
Merged

yuriw merged 5 commits into
ceph:mainfrom
kamoltat:wip-ksirivad-fix-71344

Conversation

@kamoltat

@kamoltat kamoltat commented May 21, 2025 •

Copy link
Copy Markdown
Member

Problem:

When a monitor daemon (e.g., mon.c) is killed and restarts, its
attempt to re-establish a session with a peer (mon.a) is incorrectly
rejected. This happens because mon.a retains stale connection state,
including a higher peer_global_seq, from the previous session.

When the newly restarted mon.c sends a ClientIdentFrame with a fresh
client_cookie and a low global_seq (e.g., 1), mon.a compares this
against the old connection’s peer_global_seq (e.g., 61) and mistakenly
concludes that the connection is stale. As a result, mon.a terminates
the incoming connection from mon.c, delaying session recovery and
triggering a transient MON_NETSPLIT warning. The connection is only
recovered once mon.a's backoff timer expires and it initiates a new
connection to mon.c OR when mon.c tries to connect again enough times
(each time it bumps the global_seq) such the global_seq catch's up with
what mon.a has (e.g., 61).

Solution:

Reorder the logic in handle_existing_connection so that the check for
client_cookie mismatch is performed before the global_seq comparison.
This leverages the existing code path that handles session resets and
restarts when a peer has generated a new client_cookie (e.g., after a
daemon restart). By bumping this condition earlier, we avoid
incorrectly rejecting valid new connections as "stale" and instead
allow proper session negotiation to proceed. This change prevents
unnecessary connection drops and eliminates the transient MON_NETSPLIT
in such restart scenarios.

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

Signed-off-by: Kamoltat Sirivadhna [email protected]

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)
Show available Jenkins commands

@kamoltat kamoltat self-assigned this May 21, 2025
@github-actions github-actions Bot added the tests label May 21, 2025
@kamoltat kamoltat added DNM and removed tests labels May 21, 2025
@github-actions github-actions Bot added the tests label May 22, 2025
@kamoltat
kamoltat requested a review from a team as a code owner May 22, 2025 04:13
@github-actions github-actions Bot added the core label May 22, 2025
@kamoltat
kamoltat force-pushed the wip-ksirivad-fix-71344 branch from a4d76bd to d47fb94 Compare June 4, 2025 18:45
@github-actions

github-actions Bot commented Jun 4, 2025

Copy link
Copy Markdown

Config Diff Tool Output

- removed: breakpad
! changed: rgw_sts_key: old: Key used for encrypting/ decrypting role session tokens. This key must consist of 16 hexadecimal characters, which can be generated by the command 'openssl rand -hex 16'. All radosgw instances in a zone should use the same key. In multisite configurations, all zones in a realm should use the same key.
! changed: rgw_sts_key: new: Key used for encrypting/ decrypting session token.
! changed: osd_scrub_max_interval: old: Scrub each PG no less often than this interval. Note that this option must be set at ``global`` scope, or for both ``mgr`` and``osd``.
! changed: osd_scrub_max_interval: new: Scrub each PG no less often than this interval
! changed: osd_scrub_min_interval: old: The desired interval between scrubs of a specific PG. Note that this option must be set at ``global`` scope, or for both ``mgr`` and``osd``.
! changed: osd_scrub_min_interval: new: The desired interval between scrubs of a specific PG.
! changed: osd_deep_scrub_interval: old: Deep scrub each PG (i.e., verify data checksums) at least this often. Note that this option must be set at ``global`` scope, or for both ``mgr`` and``osd``.
! changed: osd_deep_scrub_interval: new: Deep scrub each PG (i.e., verify data checksums) at least this often
! changed: osd_deep_scrub_interval_cv: old: The coefficient of variation for the deep scrub interval, specified as a ratio. On average, the next deep scrub for a PG is scheduled osd_deep_scrub_interval after the last deep scrub . The actual time is randomized to a normal distribution with a standard deviation of osd_deep_scrub_interval * osd_deep_scrub_interval_cv (clamped to within 2 standard deviations). The default value guarantees that 95% of deep scrubs will be scheduled in the range [0.8 * osd_deep_scrub_interval, 1.2 * osd_deep_scrub_interval].
! changed: osd_deep_scrub_interval_cv: new: The coefficient of variation for the deep scrub interval, specified as a ratio. On average, the next deep scrub for a PG is scheduled osd_deep_scrub_interval after the last deep scrub . The actual time is randomized to a normal distribution with a standard deviation of osd_deep_scrub_interval * osd_deep_scrub_interval_cv (clamped to within 2 standard deviations). The default value guarantees that 95% of the deep scrubs will be scheduled in the range [0.8 * osd_deep_scrub_interval, 1.2 * osd_deep_scrub_interval].
! changed: osd_deep_scrub_interval_cv: old: deep scrub intervals are varied by a random amount to prevent stampedes. This parameter determines the amount of variation. Technically ``osd_deep_scrub_interval_cv`` is the coefficient of variation for the deep scrub interval.
! changed: osd_deep_scrub_interval_cv: new: deep scrub intervals are varied by a random amount to prevent stampedes. This parameter determines the amount of variation. Technically - osd_deep_scrub_interval_cv is the coefficient of variation for the deep scrub interval.

The above configuration changes are found in the PR. Please update the relevant release documentation if necessary.

kamoltat added 2 commits June 6, 2025 19:15
Problem:
When a monitor daemon (e.g., mon.c) is killed and restarts, its
attempt to re-establish a session with a peer (mon.a) is incorrectly
rejected. This happens because mon.a retains stale connection state,
including a higher peer_global_seq, from the previous session.

When the newly restarted mon.c sends a ClientIdentFrame with a fresh
client_cookie and a low global_seq (e.g., 1), mon.a compares this
against the old connection’s peer_global_seq (e.g., 61) and mistakenly
concludes that the connection is stale. As a result, mon.a terminates
the incoming connection from mon.c, delaying session recovery and
triggering a transient MON_NETSPLIT warning. The connection is only
recovered once mon.a's backoff timer expires and it initiates a new
connection to mon.c.

Solution:
Reorder the logic in handle_existing_connection so that the check for
client_cookie mismatch is performed before the global_seq comparison.
This leverages the existing code path that handles session resets and
restarts when a peer has generated a new client_cookie (e.g., after a
daemon restart). By bumping this condition earlier, we avoid
incorrectly rejecting valid new connections as "stale" and instead
allow proper session negotiation to proceed. This change prevents
unnecessary connection drops and eliminates the transient MON_NETSPLIT
in such restart scenarios.

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

Signed-off-by: Kamoltat Sirivadhna <[email protected]>
@kamoltat
kamoltat force-pushed the wip-ksirivad-fix-71344 branch from d47fb94 to 93e15e3 Compare June 6, 2025 19:15
@kamoltat kamoltat changed the title [DNM] qa/suites/rados: debug_mon 30 ProtocolV2: make handle_existing_connection check for cookie mismatch first Jun 6, 2025
@kamoltat
kamoltat requested a review from rzarzynski June 6, 2025 19:23
@kamoltat kamoltat added messenger Issues involving one of the Ceph messenger implementations needs-tentacle-backport PRs that need tentacle back-port needs-squid-backport PR needs a squid backport and removed DNM labels Jun 6, 2025
@kamoltat

kamoltat commented Jun 8, 2025

Copy link
Copy Markdown
Member Author

jenkins test api

@kamoltat

kamoltat commented Jun 8, 2025

Copy link
Copy Markdown
Member Author

jenkins test windows

@kamoltat

kamoltat commented Jun 8, 2025

Copy link
Copy Markdown
Member Author

jenkins test make check

@kamoltat

kamoltat commented Jun 8, 2025

Copy link
Copy Markdown
Member Author

jenkins test make check arm64

@ronen-fr

Copy link
Copy Markdown
Contributor

Note a problem in the output of the Config Diff Tool

@ronen-fr

Copy link
Copy Markdown
Contributor

Is it safe to default the mon log to 30 in all regular (debug) vstarts?

@ronen-fr ronen-fr 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.

(see question)

@ronen-fr

Copy link
Copy Markdown
Contributor

Note that compilations fail due to:
/home/jenkins-build/build/workspace/ceph-pull-requests/src/msg/async/ProtocolV2.cc:1897:13: error: too many arguments provided to function-like macro invocation
1897 | dout(cct, 20) << func << dendl;

@kamoltat

kamoltat commented Jun 10, 2025 •

Copy link
Copy Markdown
Member Author

Is it safe to default the mon log to 30 in all regular (debug) vstarts?

@ronen-fr
I think as someone who regularly works on the Monitor part of Ceph using vstart, the logs are more useful at 30. But I'm open to drop it if you think it might be too verbose, personally I think it is not too verbose.

@kamoltat
kamoltat force-pushed the wip-ksirivad-fix-71344 branch from 93e15e3 to 52b9429 Compare June 10, 2025 20:14
@kamoltat

Copy link
Copy Markdown
Member Author

Note that compilations fail due to: /home/jenkins-build/build/workspace/ceph-pull-requests/src/msg/async/ProtocolV2.cc:1897:13: error: too many arguments provided to function-like macro invocation 1897 | dout(cct, 20) << func << dendl;

thank you, forgot the "l" in ldout.

@kamoltat

Copy link
Copy Markdown
Member Author

Building the branch in Shaman, will schedule a teuthlogy run targeting the mon_thrash suite to check if problem goes away.

@kamoltat

Copy link
Copy Markdown
Member Author

jenkins test windows

if (connection->policy.resetcheck) {
exproto->reset_session();
}
return reuse_connection(existing, exproto);

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.

I'm afraid this is contrary to the intention behind RetryGlobalFrame:

  CtPtr ProtocolV2::handle_reconnect(ceph::bufferlist &payload)
  {
  // ...
    if (exproto->replacing) {
      ldout(cct, 1) << __func__
                    << " existing racing replace happened while replacing."
                    << " existing=" << existing << dendl;
      auto retry = RetryGlobalFrame::Encode(exproto->peer_global_seq);
      return WRITE(retry, "session retry", read_frame);
    }
   // ...
    if (exproto->peer_global_seq > reconnect.global_seq()) {
      ldout(cct, 5) << __func__
                    << " stale global_seq: sgs=" << exproto->peer_global_seq
                    << " cgs=" << reconnect.global_seq()
                    << ", ask client to retry global" << dendl;
      auto retry = RetryGlobalFrame::Encode(exproto->peer_global_seq);
  
      INTERCEPT(18);
  
      return WRITE(retry, "session retry", read_frame);
    }

Similar machinery is present also in ProtocolV1:

CtPtr ProtocolV1::handle_connect_reply_2() {
  // ...

  if (connect_reply.tag == CEPH_MSGR_TAG_RETRY_GLOBAL) {
    global_seq = messenger->get_global_seq(connect_reply.global_seq);
    ldout(cct, 5) << __func__ << " connect got RETRY_GLOBAL "
                  << connect_reply.global_seq << " chose new " << global_seq
                  << dendl;
    return CONTINUE(send_connect_message);
  }
CtPtr ProtocolV1::handle_connect_message_2() {
  // ...
  if (existing) {
    // ...
    if (exproto->replacing) {
      ldout(cct, 1) << __func__
                    << " existing racing replace happened while replacing."
                    << " existing_state="
                    << connection->get_state_name(existing->state) << dendl;
      reply.global_seq = exproto->peer_global_seq;
      existing->lock.unlock();
      return send_connect_message_reply(CEPH_MSGR_TAG_RETRY_GLOBAL, reply,
                                        authorizer_reply);
    }             
                  
    if (connect_msg.global_seq < exproto->peer_global_seq) {
      ldout(cct, 10) << __func__ << " accept existing " << existing << ".gseq "
                     << exproto->peer_global_seq << " > "
                     << connect_msg.global_seq << ", RETRY_GLOBAL" << dendl;
      reply.global_seq = exproto->peer_global_seq;  // so we can send it below..
      existing->lock.unlock();
      return send_connect_message_reply(CEPH_MSGR_TAG_RETRY_GLOBAL, reply,
                                        authorizer_reply);
    } else {
      ldout(cct, 10) << __func__ << " accept existing " << existing << ".gseq "
                     << exproto->peer_global_seq
                     << " <= " << connect_msg.global_seq << ", looks ok"
                     << dendl;
    }

A question that is bugging me: why the V2's reconnect path is, apparently, never taken for those problematic connections?

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.

@kamoltat: have you even seen the problem on a non-lossy connection?

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.

@kamoltat: the fragment I meant during the core sync is:

CtPtr ProtocolV2::start_session_connect() {
  if (!server_cookie) {
    ceph_assert(connect_seq == 0);
    state = SESSION_CONNECTING;
    return send_client_ident();
  } else {  // reconnecting to previous session
    state = SESSION_RECONNECTING;
    ceph_assert(connect_seq > 0);
    return send_reconnect();
  }
} 

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.

I'm afraid this is contrary to the intention behind RetryGlobalFrame

Yeah, reordering peer_global_seq and client_cookie checks like that is likely to mess with MDS sessions.

@yuriw I see wip-yuri-testing label. This PR would need to go through the FS suite, preferably more than once.

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.

@kamoltat: the link with the lossy connections seems to be this:

CtPtr ProtocolV2::send_server_ident() {
  ldout(cct, 20) << __func__ << dendl;
  
  // this is required for the case when this connection is being replaced
  out_seq = discard_requeued_up_to(out_seq, 0);
  in_seq = 0;
  
  if (!connection->policy.lossy) {
    server_cookie = ceph::util::generate_random_number<uint64_t>(1, -1ll);
  }

@rzarzynski
rzarzynski requested a review from idryomov June 15, 2025 20:33
@kamoltat

kamoltat commented Jun 17, 2025 •

Copy link
Copy Markdown
Member Author

@rzarzynski In the scenario where the client is coming back to the quorum,
ProtocolV2::start_session_connect() is called upon by the client after Authentication phase between client and servers.
The client in this case will not have server_cookie and will call send_client_ident which sends the client's ident to server.
Server recieves the ident in handle_client_ident which it will look up an AsyncConnectionRef call existing and will find that it is an exisitng client which is trying to communicate. Therefore, server calls handle_existing_connection which it hits the exproto->peer_global_seq > peer_global_seq and then stop() the connection.

client does not call send_reconnect() simply because it doesn't have the server_cookie.

On the flip side, this is when we finally established the connection. The server was backed off when client went down. It hits the ms_max_backoff then wakes up 11 seconds later after the AUTH phase goes to ProtocolV2::start_session_connect(). Since server never restarted, it still has the cookie of the client (in the code it is the opposite since server is actually client at this point since it is the one establishing connection) so it will send_reconnect() and the client` who is now up and running will hit this case in handle_reconnect()

if (exproto->client_cookie != reconnect.client_cookie()) {
    ldout(cct, 1) << __func__ << " existing=" << existing
                  << " client cookie mismatch, I must have reseted:"
                  << " cc=" << std::hex << exproto->client_cookie
                  << " rcc=" << reconnect.client_cookie()
                  << ", reseting client." << std::dec
                  << dendl;
    auto reset = ResetFrame::Encode(connection->policy.resetcheck);
    return WRITE(reset, "session reset", read_frame);

All in all this leads me to think that maybe we should instead look at the logic here:

CtPtr ProtocolV2::start_session_connect() {
  if (!server_cookie) {
    ceph_assert(connect_seq == 0);
    state = SESSION_CONNECTING;
    return send_client_ident();
  } else {  // reconnecting to previous session
    state = SESSION_RECONNECTING;
    ceph_assert(connect_seq > 0);
    return send_reconnect();
  }
} 

Maybe we look at more things rather than just (!server_cookie)

@shraddhaag

Copy link
Copy Markdown
Contributor

@kamoltat

kamoltat commented Jun 19, 2025 •

Copy link
Copy Markdown
Member Author

Ah thanks for the Approval @shraddhaag, we are currently still exploring other solutions since as discussed with @rzarzynski , this one might not be the best. Holding off merging for now.

@kamoltat kamoltat changed the title ProtocolV2: make handle_existing_connection check for cookie mismatch first [DNM] ProtocolV2: make handle_existing_connection check for cookie mismatch first Jun 19, 2025
@yuriw
yuriw merged commit 6c37c2b into ceph:main Jun 19, 2025
@kamoltat

kamoltat commented Jun 19, 2025 •

Copy link
Copy Markdown
Member Author

Yikes, I guess we need to revert now lol.

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

Labels

core messenger Issues involving one of the Ceph messenger implementations needs-squid-backport PR needs a squid backport needs-tentacle-backport PRs that need tentacle back-port tests wip-yuri-testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants