Fix DeadLock in FdManager::ChangeEntityToTempPath (#2455)

commit e3b50ad introduce smart pointer to manage FdEntity

But in ChangeEntityToTempPath, we should not destroy the entity.

We should move the entry to the temp ky

Signed-off-by: liubingrun <liubr1@chinatelecom.cn>
This commit is contained in:
LiuBingrun 2024-05-11 10:29:40 +08:00 committed by GitHub
parent 3864f58c22
commit ccdcccd44c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 4 deletions

View File

@ -775,7 +775,7 @@ bool FdManager::Close(FdEntity* ent, int fd)
return false;
}
bool FdManager::ChangeEntityToTempPath(FdEntity* ent, const char* path)
bool FdManager::ChangeEntityToTempPath(const FdEntity* ent, const char* path)
{
AutoLock auto_lock(&FdManager::fd_manager_lock);
@ -783,8 +783,10 @@ bool FdManager::ChangeEntityToTempPath(FdEntity* ent, const char* path)
if(iter->second.get() == ent){
std::string tmppath;
FdManager::MakeRandomTempPath(path, tmppath);
iter->second.reset(ent);
break;
// Move the entry to the new key
fent[tmppath] = std::move(iter->second);
iter = fent.erase(iter);
return true;
}else{
++iter;
}

View File

@ -96,7 +96,7 @@ class FdManager
FdEntity* OpenExistFdEntity(const char* path, int& fd, int flags = O_RDONLY);
void Rename(const std::string &from, const std::string &to);
bool Close(FdEntity* ent, int fd);
bool ChangeEntityToTempPath(FdEntity* ent, const char* path);
bool ChangeEntityToTempPath(const FdEntity* ent, const char* path);
void CleanupCacheDir();
bool CheckAllCache();