-
Notifications
You must be signed in to change notification settings - Fork 309
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8239,20 +8239,19 @@ class CNamedGroupStore: implements INamedGroupStore, public CInterface | |
|
||
}; | ||
|
||
static CNamedGroupStore *groupStore = NULL; | ||
static CriticalSection groupsect; | ||
static std::atomic<CNamedGroupStore *> groupStore{nullptr}; | ||
|
||
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); | ||
|
@@ -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()); | ||
} | ||
|
||
// -------------------------------------------------------- | ||
|
@@ -9204,8 +9200,7 @@ GetFileClusterNamesType CDistributedFileDirectory::getFileClusterNames(const cha | |
// -------------------------------------------------------- | ||
|
||
|
||
static CDistributedFileDirectory *DFdir = NULL; | ||
static CriticalSection dfdirCrit; | ||
static std::atomic<CDistributedFileDirectory *> DFdir{nullptr}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
@@ -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 | ||
{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
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()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ghalliday would it be safer to move up the |
||
{ | ||
::Release(groupStore.load()); | ||
groupStore.store(nullptr); | ||
} | ||
DFdir = NULL; | ||
CriticalBlock block2(groupsect); | ||
::Release(groupStore); | ||
groupStore = NULL; | ||
} | ||
|
||
class CDFPartFilter : implements IDFPartFilter, public CInterface | ||
|
There was a problem hiding this comment.
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.