#3665·seastar

指标:分配失败可能终止构建/拆除或留下过时的注册

作者: VikramAditya33创建于 2026年9月3日更新于 2026年9月3日
  1. Allocating constructors are declared noexcept The default metric_groups constructor is declared and defined as noexcept, but it calls create_metric_groups(), which allocates a metric_groups_impl using std::make_unique. Consequently, an allocation failure calls std::terminate instead of propagating std::bad_alloc. metric_group() inherits the same behavior through its base constructor. Relevant code: - https://GitHub.com/scylladb/seastar/blob/9b95b250cc64af11b84fa5ea3d677f76b37fdef0/include/seastar/core/metrics_registration.hh#L90-L102 - https://GitHub.com/scylladb/seastar/blob/9b95b250cc64af11b84fa5ea3d677f76b37fdef0/include/seastar/core/metrics_registration.hh#L151-L169 - https://GitHub.com/scylladb/seastar/blob/9b95b250cc64af11b84fa5ea3d677f76b37fdef0/src/core/metrics.cc#L43-L50 - https://GitHub.com/scylladb/seastar/blob/9b95b250cc64af11b84fa5ea3d677f76b37fdef0/src/core/metrics.cc#L332-L334 The initializer-list constructor and metric_groups::clear() perform the same underlying allocation without being declared noexcept, which makes the default constructor’s specification appear accidental. 2. metric_definition also allocates under noexcept The constructor that creates a public metric_definition from metric_definition_impl is declared noexcept, but its implementation uses std::make_unique. This is reached through metric factory functions such as make_gauge() and make_counter(). An injected allocation failure therefore terminates instead of propagating. Relevant code: - https://GitHub.com/scylladb/seastar/blob/9b95b250cc64af11b84fa5ea3d677f76b37fdef0/include/seastar/core/metrics_registration.hh#L63-L70 - https://GitHub.com/scylladb/seastar/blob/9b95b250cc64af11b84fa5ea3d677f76b37fdef0/src/core/metrics.cc#L74-L82 metric_definition_impl::aggregate() has the same problem: it is declared noexcept, but reserves vector capacity and copies label-name strings. Relevant code: - https://ZZTERM7ZZ.com/scylladb/seastar/blob/9b95b250cc64af11b84fa5ea3d677f76b37fdef0/src/core/metrics.cc#L100-L105

内容来源: scylladb/seastar