-
Type:
Bug
-
Resolution: Unresolved
-
Priority:
Minor - P4
-
None
-
Affects Version/s: None
-
Component/s: None
-
ALL
-
-
None
-
None
-
None
-
None
-
None
-
None
-
None
In src/mongo/db/topology/cluster_parameters/cluster_server_parameter_refresher.h (formerly src/mongo/idl/cluster_server_parameter_refresher.h), the member _lastFcv of type multiversion::FeatureCompatibilityVersion (an enum class) has no default member initializer. The class currently declares no user-provided constructor, so the compiler-generated default constructor leaves _lastFcv with an indeterminate value.
In ClusterServerParameterRefresher::start(), the object is created with std::make_unique<ClusterServerParameterRefresher>() and _lastFcv is indeterminate until it is explicitly assigned a few lines later, before the periodic refresh job that reads it (_refreshParameters() compares fcv != _lastFcv) is started. In the current flow the assignment happens before any read, so the defect is latent rather than an active read of an uninitialized value; however, the member is still left uninitialized by construction, which is fragile — any future path that reads _lastFcv before the assignment (e.g. a differently-ordered start, or a new construction site) would be undefined behavior.
The enum defines sentinel values such as kInvalid and kUnsetDefaultLastLTSBehavior intended for exactly this "unset" state, but none is used as a default.
Found by static analysis (Svace, UNINIT.CTOR): "Constructor may not initialize class members of 'mongo::ClusterServerParameterRefresher'. Following members aren't initialized: _lastFcv." (The originally flagged explicit ClusterServerParameterRefresher() = default; line has since been removed, but the underlying uninitialized member remains.)
Suggested fix: give the member a default initializer, e.g. multiversion::FeatureCompatibilityVersion _lastFcv = multiversion::FeatureCompatibilityVersion::kInvalid;.