Skip to content

Harden core perf-counters and worker affinity against config-driven aborts - #273

Merged
HX L (linmajia) merged 1 commit into
microsoft:masterfrom
linmajia:fix
Jul 21, 2026
Merged

Harden core perf-counters and worker affinity against config-driven aborts#273
HX L (linmajia) merged 1 commit into
microsoft:masterfrom
linmajia:fix

Conversation

@linmajia

Copy link
Copy Markdown
Contributor

Summary

Robustness hardening for the rDSN core runtime, plus a submodule pointer
update that pulls in the merged meta/replica-server hardening.

Each core change replaces an always-on dassert(...) — which calls
dsn_coredump()SIGABRT in all build configurations, not just debug —
on a recoverable condition (operator-supplied config or a missing
service-node context) with graceful derror/dwarn + fallback. None of these
conditions should take a production process down; they are now logged and
handled.

Changes

src/core/src/perf_counters.cpp

  • perf_counters ctor[core] perf_counter_max_count is operator-supplied.
    A value of 0 or an unreasonably large one (>= 1000000) used to abort the
    whole process (and a huge value would also overflow / OOM the
    _quick_counters allocation). Now falls back to the default 10000 with a
    dwarn instead of crashing on bad config.
  • dsn_perf_counter_create — aborted when called outside a service-node
    context. Now returns nullptr with a derror so the caller can handle it.

src/core/src/task_worker.cpp

  • set_affinityworker_affinity_mask is operator-supplied.
    • An empty mask (0) used to abort; it now warns and skips setting affinity.
    • A mask referencing a nonexistent CPU used to abort; it is now clamped to the
      available CPUs with a dwarn (and skips setting affinity if nothing valid
      remains).
    • When hardware_concurrency() returns 0 (CPU count unknown), the old
      ((1 << 0) - 1) == 0 bound rejected every nonzero mask; that case now
      defers to the OS call, which already warns (not aborts) on failure.
    • The nr_cpu < 64 upper bound is kept intentionally: the mask is a
      uint64_t (only addresses CPUs 0–63), and computing (1 << nr_cpu) for
      nr_cpu >= 64 would be undefined behavior. Documented inline.
    • Added #include <cinttypes> for the PRIx64 format macros.

Submodule: src/plugins_ext/rDSN.dist.service

Bumped to the merged master, which hardens the meta-server and replica-server
against config, ZooKeeper-race, and load-balancer aborts, and fixes a
modulo-by-zero (SIGFPE) in the mutation cache
(rDSN.dist.service#40).

Testing

Builds cleanly as part of the full plugin build
(./run.sh build --build_plugins) on Ubuntu.

Round 87 of the robustness campaign. Three always-on assertions on recoverable
conditions in dsn core were converted to graceful degradation, so bad
operator-supplied config or a missing service-node context no longer aborts the
process (dassert -> dsn_coredump -> SIGABRT). Also bumps the rDSN.dist.service
submodule to its Round-87 fixes.

perf_counters.cpp
  - perf_counters ctor: [core] perf_counter_max_count of 0, or an unreasonably
    large value, aborted the process here; a huge value would also overflow / OOM
    the _quick_counters (new perf_counter*[]) allocation below. Fall back to the
    default (10000) with a warning instead of crashing on bad config.
  - dsn_perf_counter_create: returning without a current service node
    (get_current_node2() == nullptr) aborted; return nullptr with an error like
    every other bad-input path in this public C API.

task_worker.cpp (set_affinity)
  [core] worker_affinity_mask is operator-supplied. A mask that references a
  nonexistent cpu aborted the process, and when hardware_concurrency() cannot
  determine the cpu count (returns 0) the old ((1<<0)-1)==0 bound rejected every
  nonzero mask. Skip on an empty mask, clamp the mask to the available cpus (with
  a warning) when the count is known, and otherwise defer to the OS call below
  (which already warns, not aborts, on failure). The nr_cpu < 64 guard is
  retained deliberately: the mask is a uint64_t so it can only address cpus
  0..63, and computing (1 << nr_cpu) for nr_cpu >= 64 would be a shift by >= the
  operand width (undefined behavior). Adds <cinttypes> for the PRIx64 macros.

submodule: bump rDSN.dist.service to 631ced1 (Round-87 config / ZooKeeper-race /
load-balancer abort fixes).

Build-verified with a clean plugin build (CC=gcc-8 CXX=g++-8, --build_plugins) on
Ubuntu 16.04; no tests run.
@linmajia
HX L (linmajia) merged commit 043f051 into microsoft:master Jul 21, 2026
2 checks passed
@linmajia
HX L (linmajia) deleted the fix branch July 21, 2026 08:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant