Skip to content

Commit

Permalink
bug mongo: fix UB on stop
Browse files Browse the repository at this point in the history
  • Loading branch information
segoon committed Dec 12, 2023
1 parent 99bad8b commit b65445d
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 2 deletions.
1 change: 1 addition & 0 deletions core/include/userver/congestion_control/controllers/v2.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class Controller {
virtual ~Controller() = default;

void Start();
void Stop();

void Step();

Expand Down
2 changes: 2 additions & 0 deletions core/src/congestion_control/controllers/v2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ void Controller::Start() {
}
}

void Controller::Stop() { periodic_.Stop(); }

std::string_view Controller::LogFakeMode() const {
if (config_.fake_mode)
return " (fake mode)";
Expand Down
2 changes: 2 additions & 0 deletions mongo/include/userver/storages/mongo/pool.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ class Pool {
~Pool();

void Start();

void Stop();
/// @endcond

/// Checks whether a collection exists
Expand Down
6 changes: 5 additions & 1 deletion mongo/src/storages/mongo/component.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,11 @@ Mongo::Mongo(const ComponentConfig& config, const ComponentContext& context)
{{"mongo_database", section_name}});
}

Mongo::~Mongo() { statistics_holder_.Unregister(); }
Mongo::~Mongo() {
pool_->Stop();

statistics_holder_.Unregister();
}

storages::mongo::PoolPtr Mongo::GetPool() const { return pool_; }

Expand Down
8 changes: 7 additions & 1 deletion mongo/src/storages/mongo/multi_mongo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,13 @@ void MultiMongo::PoolSet::AddPool(std::string dbalias) {
}

bool MultiMongo::PoolSet::RemovePool(const std::string& dbalias) {
return pool_map_ptr_->erase(dbalias);
auto it = pool_map_ptr_->find(dbalias);
if (it != pool_map_ptr_->end()) {
it->second->Stop();
return pool_map_ptr_->erase(it) != pool_map_ptr_->end();
} else {
return false;
}
}

void MultiMongo::PoolSet::Activate() {
Expand Down
2 changes: 2 additions & 0 deletions mongo/src/storages/mongo/pool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ Pool::Pool(std::string id, const std::string& uri,

void Pool::Start() { impl_->Start(); }

void Pool::Stop() { impl_->Stop(); }

Pool::~Pool() = default;

void Pool::DropDatabase() {
Expand Down
2 changes: 2 additions & 0 deletions mongo/src/storages/mongo/pool_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ PoolImpl::PoolImpl(std::string&& id, const PoolConfig& static_config,

void PoolImpl::Start() { cc_controller_.Start(); }

void PoolImpl::Stop() { cc_controller_.Stop(); }

void PoolImpl::OnConfigUpdate(const dynamic_config::Snapshot& config) {
cc_controller_.SetEnabled(config[kCongestionControlEnabled]);
}
Expand Down
1 change: 1 addition & 0 deletions mongo/src/storages/mongo/pool_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class PoolImpl {
virtual ~PoolImpl() = default;

void Start();
void Stop();

const std::string& Id() const;
const stats::PoolStatistics& GetStatistics() const;
Expand Down

0 comments on commit b65445d

Please sign in to comment.