Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix TSAN issue related to db_paths_lock #9868

Merged
merged 1 commit into from Dec 2, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/main/database_manager.cpp
Expand Up @@ -94,7 +94,12 @@ optional_ptr<AttachedDatabase> DatabaseManager::GetDatabaseFromPath(ClientContex

void DatabaseManager::CheckPathConflict(ClientContext &context, const string &path) {
// ensure that we did not already attach a database with the same path
if (db_paths.find(path) != db_paths.end()) {
bool path_exists;
{
lock_guard<mutex> path_lock(db_paths_lock);
path_exists = db_paths.find(path) != db_paths.end();
}
if (path_exists) {
// check that the database is actually still attached
auto entry = GetDatabaseFromPath(context, path);
if (entry) {
Expand All @@ -109,8 +114,8 @@ void DatabaseManager::InsertDatabasePath(ClientContext &context, const string &p
return;
}

lock_guard<mutex> path_lock(db_paths_lock);
CheckPathConflict(context, path);
lock_guard<mutex> path_lock(db_paths_lock);
db_paths.insert(path);
}

Expand Down Expand Up @@ -141,7 +146,6 @@ void DatabaseManager::GetDatabaseType(ClientContext &context, string &db_type, A

// try to extract database type from path
if (db_type.empty()) {
lock_guard<mutex> path_lock(db_paths_lock);
CheckPathConflict(context, info.path);

DBPathAndType::CheckMagicBytes(info.path, db_type, config);
Expand Down