← Back to Pull requests

Restart the discovery service instead of aborting the gateway #2193

Open
unknown opened this pull request with 385 lines diff across 4 files
View on GitHub
unknown unknown commented on Oct 03, 2026 09:18 UTC
Author

Fixes: #1342

What changed


Today, when the discovery service sub-process terminates, the SIGCHLD handler raises SystemExit and the whole gateway goes down. With this change:

  • The SIGCHLD handler is now a GatewayServer method. If the terminated child is the discovery service, it schedules a restart instead of exiting. Any other child (SPDK, monitor client) still aborts the gateway exactly as before.

  • The restart is done from the keep_alive() loop (main thread) after restart_interval seconds, not from the signal handler, so the gateway keeps serving without a discovery service in the meantime.

  • After more than restart_attempts_limit consecutive failures the gateway aborts, with the same Gateway subprocess terminated pid=... exit_code=... message as today. A discovery service that ran for at least 60 seconds resets the consecutive failures count, so an occasional crash on a long-running gateway doesn't accumulate toward the limit.

  • _start_discovery_service() is split so the fork part (_fork_discovery_service()) can be reused for restarts. The SPDK discovery subsystem deletion still only happens on the initial start.

  • The child reaping logic moved to reap_child_process(); the old module-level sigchld_handler had no other users and was removed.
  • New options in the [discovery] section (documented in ceph-nvmeof.conf):

    | Option | Default | Meaning |
    |---|---|---|
    | restart_attempts_limit | 3 | Consecutive restarts before giving up. 0 keeps the old behavior (abort on the first failure). |
    | restart_interval | 5.0 | Seconds to wait before restarting. |

    Tests


  • test_server.py::test_discovery_exit and test_discovery_bind.py::test_discovery_bind_abort assert the old abort-on-first-failure behavior, so they now set restart_attempts_limit = 0 (on a copy of the config) to keep covering that path.

  • New test_server.py::test_discovery_restart: kills the discovery service, runs keep_alive() and checks a new discovery process was started; then kills it again and checks the gateway aborts once over the limit.
  • flake8 passes. I don't have the containerized environment locally, so I exercised the new methods against a stub server with a fake clock (restarts up to the limit then abort, the 60s reset, 0 = old behavior, non-discovery child still aborts) and am relying on CI for the real tests.

    Notes for reviewers


  • Forking after the gRPC server is running: the initial fork happens before the gRPC server starts, but a restart forks from the running gateway, which already has gRPC (and rados) threads. The discovery child doesn't use gRPC and already resets the inherited signal handlers, so I expect this to be fine, but it's a difference worth pointing out. An alternative would be to spawn python3 -m control.discovery with subprocess, but that would lose in-memory config overrides that tests rely on, so I kept the existing fork model.

  • @Annmool asked to take this issue last year but it was never assigned and I couldn't find a PR. Happy to coordinate if they're still working on it.
  • Diff: 385 lines (+288 / -97) across 4 files Reviewer: baum Review duration: 57289m
    All Vouch review confidence checks passed
    Residual risk 0.28 = Change Risk (0.50) × (1 − Review Confidence (0.45)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.50 · 385 lines diff across 4 files
    0.50
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    44%
    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.356
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #2193"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 44.7% 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: 50% (MEDIUM) · Higher = larger blast radius
    50%
    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: 44.7% · Lower = rushed or shallow review
    44.7%
    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: 27.7% · Safe to merge
    27.7%