指标:分配失败可能终止构建/拆除或留下过时的注册
作者: VikramAditya33创建于 2026年9月3日更新于 2026年9月3日
- Allocating constructors are declared
noexceptThe defaultmetric_groupsconstructor is declared and defined asnoexcept, but it callscreate_metric_groups(), which allocates ametric_groups_implusingstd::make_unique. Consequently, an allocation failure callsstd::terminateinstead of propagatingstd::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 andmetric_groups::clear()perform the same underlying allocation without being declarednoexcept, which makes the default constructor’s specification appear accidental. 2.metric_definitionalso allocates undernoexceptThe constructor that creates a publicmetric_definitionfrommetric_definition_implis declarednoexcept, but its implementation usesstd::make_unique. This is reached through metric factory functions such asmake_gauge()andmake_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-L82metric_definition_impl::aggregate()has the same problem: it is declarednoexcept, 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