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

HPCC-33586 fix double checked locking pattern for CNamedGroupStore in dali #19585

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 32 additions & 36 deletions dali/base/dadfs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8239,20 +8239,19 @@ class CNamedGroupStore: implements INamedGroupStore, public CInterface

};

static CNamedGroupStore *groupStore = NULL;
static CriticalSection groupsect;
static std::atomic<CNamedGroupStore *> groupStore{nullptr};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There seems to be a mixture of fixes here. Either the variable should be atomic, or it should be accessed within a critical section. No need to do both.


bool CNamedGroupIterator::match()
{
if (conn.get()) {
if (matchgroup.get()) {
if (!groupStore)
if (!groupStore.load())
return false;
const char *name = pe->query().queryProp("@name");
if (!name||!*name)
return false;
GroupType dummy;
Owned<IGroup> lgrp = groupStore->dolookup(name, conn, NULL, dummy);
Owned<IGroup> lgrp = groupStore.load()->dolookup(name, conn, NULL, dummy);
if (lgrp) {
if (exactmatch)
return lgrp->equals(matchgroup);
Expand All @@ -8266,14 +8265,11 @@ bool CNamedGroupIterator::match()
return false;
}

INamedGroupStore &queryNamedGroupStore()
INamedGroupStore &queryNamedGroupStore()
{
if (!groupStore) {
CriticalBlock block(groupsect);
if (!groupStore)
groupStore = new CNamedGroupStore();
}
return *groupStore;
if (!groupStore.load())
groupStore.store(new CNamedGroupStore());
return *(groupStore.load());
}

// --------------------------------------------------------
Expand Down Expand Up @@ -9204,8 +9200,7 @@ GetFileClusterNamesType CDistributedFileDirectory::getFileClusterNames(const cha
// --------------------------------------------------------


static CDistributedFileDirectory *DFdir = NULL;
static CriticalSection dfdirCrit;
static std::atomic<CDistributedFileDirectory *> DFdir{nullptr};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar comments to above - either make it atomic, or protect all access within a critical section.


/**
* Public method to control DistributedFileDirectory access
Expand All @@ -9214,38 +9209,39 @@ static CriticalSection dfdirCrit;
*/
IDistributedFileDirectory &queryDistributedFileDirectory()
{
if (!DFdir) {
CriticalBlock block(dfdirCrit);
if (!DFdir)
DFdir = new CDistributedFileDirectory();
}
return *DFdir;
if (!DFdir.load())
DFdir.store(new CDistributedFileDirectory());
return *DFdir.load();
}

/**
* Shutdown distributed file system (root directory).
*/
void closedownDFS() // called by dacoven
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is closedownDFS() ever called - I don't think so. If not the function can be deleted, avoiding the lifetime problem above.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

closedownDFS() is called from dali/base/dacoven.cpp :

image

CriticalBlock block(dfdirCrit);
try {
delete DFdir;
}
catch (IMP_Exception *e) {
if (e->errorCode()!=MPERR_link_closed)
throw;
PrintExceptionLog(e,"closedownDFS");
e->Release();
if (DFdir.load())
{
try {
delete DFdir.load();
}
catch (IMP_Exception *e) {
if (e->errorCode()!=MPERR_link_closed)
throw;
PrintExceptionLog(e,"closedownDFS");
e->Release();
}
catch (IDaliClient_Exception *e) {
if (e->errorCode()!=DCERR_server_closed)
throw;
e->Release();
}
DFdir.store(nullptr);
}
catch (IDaliClient_Exception *e) {
if (e->errorCode()!=DCERR_server_closed)
throw;
e->Release();
if (groupStore.load())
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ghalliday would it be safer to move up the groupStore release before the DFdir delete in case the DFdir delete ends up throwing an exception? Or not bother?

{
::Release(groupStore.load());
groupStore.store(nullptr);
}
DFdir = NULL;
CriticalBlock block2(groupsect);
::Release(groupStore);
groupStore = NULL;
}

class CDFPartFilter : implements IDFPartFilter, public CInterface
Expand Down
Loading