← Back to Pull requests

discovery: notify every pending host, not just the first one #1977

Merged
tchaikov merged 1 files (27 lines) on Jul 29, 2026 02:48 UTC
View on GitHub
tchaikov tchaikov commented on Jul 03, 2026 13:49 UTC
Author

_state_notify_update() returned right after completing the async event of the first connection with a parked AER, on the error paths too, so when a subsystem or listener change fired, only one of the hosts with a persistent discovery connection learned about it; the rest kept waiting on AERs that never complete. A dead connection was worse: BrokenPipeError returned before any remaining host was notified.

AENs complete per controller, so send the Discovery Log Page Change notice to every parked AER: loop over all connections, continue past send failures, and let the keep-alive reaper collect the dead ones.

Take self.lock while walking conn_vals, like every other accessor (nvmeof_tcp_connection, nvmeof_accept, handle_timeout): this function runs on the state-update thread, racing the reaper's del. The payload is a 40-byte AEN on a non-blocking socket, so holding the lock across the loop is fine.

break_interval stays unused: it paces heavy RPC batches in server.py's version of this callback, but here it would only delay notifications, and sleeping under the lock would stall the request path.

Fixes #1976

Diff: 27 lines (+16 / -11) across 1 files Reviewer: leonidc Review duration: 36779m
All Vouch review confidence checks passed
Residual risk 0.04 = Change Risk (0.23) × (1 − Review Confidence (0.83)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.23 · 27 lines diff across 1 files
0.23
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.83 · 5 substantive comment(s)
0.83
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 50%
83%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.199
Real PR Conversation Timeline
19 items
copilot-pull-request-reviewer[bot] copilot-pull-request-reviewer[bot] commented on Jul 03, 2026 13:52 UTC
Reviewer

Pull request overview

This PR fixes Discovery Service AEN delivery so that all hosts with a parked AER (persistent discovery connection) get notified when subsystems/listeners change, rather than only the first eligible connection being notified (or notifications aborting early on send errors). It also makes the notification loop concurrency-safe by holding self.lock while traversing conn_vals, avoiding races with connection reaping.

Changes:

  • Iterate over all connections with recv_async set and send the “Discovery Log Page Change” async event to each one (no early return after the first send).

  • Hold self.lock while walking self.conn_vals to avoid concurrent mutation while notifying.

  • On BrokenPipeError / OSError, log and continue notifying other hosts instead of aborting the whole notification pass.
  • ---

    💡 <a href="/ceph/ceph-nvmeof/new/devel?filename=.github/instructions/*.instructions.md" class="Link--inTextBlock" target="_blank" rel="noopener noreferrer">Add Copilot custom instructions</a> for smarter, more guided reviews. <a href="https://docs.github.com/en/copilot/customizing-copilot/adding-repository-custom-instructions-for-github-copilot" class="Link--inTextBlock" target="_blank" rel="noopener noreferrer">Learn how to get started</a>.

    Copilot Copilot commented on code on Jul 03, 2026 13:54 UTC
    Code Review
    control/discovery.py:1
    @@ -1071,20 +1073,21 @@ def _state_notify_update(self, update, is_add_req, break_interval):
                     async_reply = CqeNVMe()
                     # async_event_type:0x2 async_event_info:0xf0 log_page_identifier:0x70
                     async_reply.dword0 = int.from_bytes(b'\x02\xf0\x70\x00', byteorder='little')
    -                async_reply.sq_head_ptr = self.conn_vals[key].sq_head_ptr
    -                async_reply.cmd_id = self.conn_vals[key].async_cmd_id
    +                async_reply.sq_head_ptr = self_conn.sq_head_ptr
    +                async_reply.cmd_id = self_conn.async_cmd_id
     
                     try:
    -                    self.conn_vals[key].connection.sendall(pdu_reply + async_reply)
    +                    self_conn.connection.sendall(pdu_reply + async_reply)
                     except BrokenPipeError:
    +                    # let handle_timeout() reap the dead connection, keep
    +                    # notifying the other hosts
                         self.logger.error("client disconnected unexpectedly.")

    The BrokenPipeError log message doesn’t identify which discovery connection/controller disconnected, which makes triage difficult now that notifications iterate over all connections.

    Copilot Copilot commented on code on Jul 03, 2026 13:54 UTC
    Code Review
    control/discovery.py:1
    @@ -1071,20 +1073,21 @@ def _state_notify_update(self, update, is_add_req, break_interval):
                     async_reply = CqeNVMe()
                     # async_event_type:0x2 async_event_info:0xf0 log_page_identifier:0x70
                     async_reply.dword0 = int.from_bytes(b'\x02\xf0\x70\x00', byteorder='little')
    -                async_reply.sq_head_ptr = self.conn_vals[key].sq_head_ptr
    -                async_reply.cmd_id = self.conn_vals[key].async_cmd_id
    +                async_reply.sq_head_ptr = self_conn.sq_head_ptr
    +                async_reply.cmd_id = self_conn.async_cmd_id
     
                     try:
    -                    self.conn_vals[key].connection.sendall(pdu_reply + async_reply)
    +                    self_conn.connection.sendall(pdu_reply + async_reply)
                     except BrokenPipeError:
    +                    # let handle_timeout() reap the dead connection, keep
    +                    # notifying the other hosts
                         self.logger.error("client disconnected unexpectedly.")
    -                    return
    +                    continue
                     except OSError as ex:
                         self.logger.exception(f"got OS error {ex.errno}: {ex.strerror}")

    This exception log would be more actionable if it included which connection triggered the OSError (e.g., socket/fileno), especially since the loop continues to notify other hosts.

    copilot-pull-request-reviewer[bot] copilot-pull-request-reviewer[bot] commented on Jul 03, 2026 13:54 UTC
    Reviewer

    Pull request overview

    Copilot reviewed 1 out of 1 changed files in this pull request and generated 2 comments.

    tchaikov tchaikov commented on code on Jul 03, 2026 14:19 UTC
    Code Review
    control/discovery.py:1
    @@ -1071,20 +1073,21 @@ def _state_notify_update(self, update, is_add_req, break_interval):
                     async_reply = CqeNVMe()
                     # async_event_type:0x2 async_event_info:0xf0 log_page_identifier:0x70
                     async_reply.dword0 = int.from_bytes(b'\x02\xf0\x70\x00', byteorder='little')
    -                async_reply.sq_head_ptr = self.conn_vals[key].sq_head_ptr
    -                async_reply.cmd_id = self.conn_vals[key].async_cmd_id
    +                async_reply.sq_head_ptr = self_conn.sq_head_ptr
    +                async_reply.cmd_id = self_conn.async_cmd_id
     
                     try:
    -                    self.conn_vals[key].connection.sendall(pdu_reply + async_reply)
    +                    self_conn.connection.sendall(pdu_reply + async_reply)
                     except BrokenPipeError:
    +                    # let handle_timeout() reap the dead connection, keep
    +                    # notifying the other hosts
                         self.logger.error("client disconnected unexpectedly.")

    fixed

    tchaikov tchaikov commented on code on Jul 03, 2026 14:19 UTC
    Code Review
    control/discovery.py:1
    @@ -1071,20 +1073,21 @@ def _state_notify_update(self, update, is_add_req, break_interval):
                     async_reply = CqeNVMe()
                     # async_event_type:0x2 async_event_info:0xf0 log_page_identifier:0x70
                     async_reply.dword0 = int.from_bytes(b'\x02\xf0\x70\x00', byteorder='little')
    -                async_reply.sq_head_ptr = self.conn_vals[key].sq_head_ptr
    -                async_reply.cmd_id = self.conn_vals[key].async_cmd_id
    +                async_reply.sq_head_ptr = self_conn.sq_head_ptr
    +                async_reply.cmd_id = self_conn.async_cmd_id
     
                     try:
    -                    self.conn_vals[key].connection.sendall(pdu_reply + async_reply)
    +                    self_conn.connection.sendall(pdu_reply + async_reply)
                     except BrokenPipeError:
    +                    # let handle_timeout() reap the dead connection, keep
    +                    # notifying the other hosts
                         self.logger.error("client disconnected unexpectedly.")
    -                    return
    +                    continue
                     except OSError as ex:
                         self.logger.exception(f"got OS error {ex.errno}: {ex.strerror}")

    incorporated.

    copilot-pull-request-reviewer[bot] copilot-pull-request-reviewer[bot] commented on Jul 04, 2026 13:30 UTC
    Reviewer

    Pull request overview

    Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.

    leonidc leonidc commented on Jul 05, 2026 12:46 UTC
    Contributor

    Looks good to me
    We will update the state of this PR after more testing

    leonidc leonidc approved these changes on Jul 05, 2026 12:47 UTC
    Approved Reviewer

    lgtm

    tchaikov tchaikov commented on Jul 17, 2026 12:00 UTC
    Author

    @leonidc may i learn how the test is going? is there anything i can do on my end?

    caroav caroav commented on Jul 19, 2026 11:57 UTC
    Contributor

    @leonidc may i learn how the test is going? is there anything i can do on my end?

    @tchaikov sorry for the delay. we have some additional automation that is not a part of upstream yet that we use. Most of the tests are covered in teuthology but we also want to verify using the additional tests. Will run it an update in few days max.

    caroav caroav commented on Jul 27, 2026 08:04 UTC
    Contributor

    @tchaikov please merge it. Some tests failed because of a known regression introduced last week to ceph main (see https://github.com/ceph/ceph/pull/70461). Other than that testing looks good.

    caroav caroav approved these changes on Jul 27, 2026 08:04 UTC
    Approved Reviewer

    Approved these changes.

    Copilot Copilot commented on code on Jul 27, 2026 12:57 UTC
    Code Review
    control/discovery.py:1
    @@ -1061,8 +1061,10 @@ def _state_notify_update(self, update, is_add_req, break_interval):
             if not should_send_async_event:
                 return
     
    -        for key in list(self.conn_vals.keys()):
    -            if self.conn_vals[key].recv_async is True:
    +        with self.lock:
    +            for self_conn in self.conn_vals.values():
    +                if not self_conn.recv_async:
    +                    continue

    The updated notification loop changes behavior from “notify first parked AER only” to “notify every connection with a parked AER and continue past send failures”. There isn’t test coverage validating (a) all pending discovery connections are notified on a state update and (b) a send failure on one connection does not prevent others from being notified, which is the core regression being fixed here.

    copilot-pull-request-reviewer[bot] copilot-pull-request-reviewer[bot] commented on Jul 27, 2026 12:57 UTC
    Reviewer

    Pull request overview

    Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.

    tchaikov tchaikov commented on Jul 27, 2026 12:58 UTC
    Author

    @tchaikov please merge it. Some tests failed because of a known regression introduced last week to ceph main (see ceph/ceph#70461). Other than that testing looks good.

    @caroav hi Aviv, thanks for reviewing this change and approving it. but i am not able to merge it, as you noticed, some tests failed, and they are "required" to pass. i just rebased against devel HEAD in hope to retrigger the test.

    Copilot Copilot commented on code on Jul 28, 2026 10:31 UTC
    Code Review
    control/discovery.py:1
    @@ -1071,20 +1073,23 @@ def _state_notify_update(self, update, is_add_req, break_interval):
                     async_reply = CqeNVMe()
                     # async_event_type:0x2 async_event_info:0xf0 log_page_identifier:0x70
                     async_reply.dword0 = int.from_bytes(b'\x02\xf0\x70\x00', byteorder='little')
    -                async_reply.sq_head_ptr = self.conn_vals[key].sq_head_ptr
    -                async_reply.cmd_id = self.conn_vals[key].async_cmd_id
    +                async_reply.sq_head_ptr = self_conn.sq_head_ptr
    +                async_reply.cmd_id = self_conn.async_cmd_id
     
                     try:
    -                    self.conn_vals[key].connection.sendall(pdu_reply + async_reply)
    +                    self_conn.connection.sendall(pdu_reply + async_reply)

    nvmeof_accept() sets each discovery socket to non-blocking (conn.setblocking(False)), but _state_notify_update() uses sendall() directly. On non-blocking sockets, sendall() can raise BlockingIOError (EAGAIN) and may do partial writes before failing, which risks sending a truncated PDU/CQE and corrupting framing. Consider forcing the socket to blocking just for this small AEN send (under the lock) so the payload is sent atomically, or implement a proper buffered write path.

    copilot-pull-request-reviewer[bot] copilot-pull-request-reviewer[bot] commented on Jul 28, 2026 10:31 UTC
    Reviewer

    Pull request overview

    Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.

    Reviewers
    Assignees
    tchaikov tchaikov
    Labels
    risk: low confidence: 83.4% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 22.9% (LOW) · Higher = larger blast radius
    22.9%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 83.4% · Lower = rushed or shallow review
    83.4%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 3.8% · Safe to merge
    3.8%