Skip to content

Commit

Permalink
Fix DeadLock in FdManager::ChangeEntityToTempPath (#2455)
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
VVoidV committed May 11, 2024
1 parent 3864f58 commit ccdcccd
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
8 changes: 5 additions & 3 deletions src/fdcache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -775,16 +775,18 @@ 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);

for(fdent_map_t::iterator iter = fent.begin(); iter != fent.end(); ){
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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/fdcache.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit ccdcccd

Please sign in to comment.