Skip to content

Commit cf3b46f

Browse files
ISSUE-76 : Fix race condition during aggressive reloads (#189)
* ISSUE-76 : Fix race condition during aggressive reloads Reason for Change: moving reportThread out of profilexconf structure and making it static in the file, this helps in reuse without depending on profilexconf structure Test Procedure: Aggressively simulate report uploads and verify that no crashes occur. Risks: Medium Priority: P1 * Minor Fix * Coverity Fix * coverity fix * Coverity Fix debug --------- Co-authored-by: Shibu Kakkoth Vayalambron <shibu.kakkoth@gmail.com>
1 parent 4d5253b commit cf3b46f

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

source/bulkdata/profilexconf.c

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,11 @@ static void* CollectAndReportXconf(void* data)
220220
do
221221
{
222222
T2Info("%s while Loop -- START \n", __FUNCTION__);
223+
if(singleProfile == NULL)
224+
{
225+
T2Error("%s is called with empty profile, profile reload might be in-progress, skip the request\n", __FUNCTION__);
226+
goto reportXconfThreadEnd;
227+
}
223228
profile = singleProfile;
224229
Vector *profileParamVals = NULL;
225230
Vector *grepResultList = NULL;
@@ -498,7 +503,6 @@ static void* CollectAndReportXconf(void* data)
498503
//pthread_mutex_unlock(&plMutex);
499504
reportXconfThreadEnd :
500505
T2Info("%s while Loop -- END \n", __FUNCTION__);
501-
T2Info("%s --out\n", __FUNCTION__);
502506
pthread_cond_wait(&reuseThread, &plMutex);
503507
}
504508
while(initialized);
@@ -596,7 +600,6 @@ T2ERROR ProfileXConf_uninit()
596600
pthread_cond_signal(&reuseThread);
597601
pthread_mutex_unlock(&plMutex);
598602
pthread_join(singleProfile->reportThread, NULL);
599-
reportThreadExits = false;
600603
singleProfile->reportInProgress = false ;
601604
T2Info("Final report is completed, releasing profile memory\n");
602605
}
@@ -731,21 +734,13 @@ T2ERROR ProfileXConf_delete(ProfileXConf *profile)
731734

732735
if(singleProfile->reportInProgress)
733736
{
734-
T2Info("Waiting for CollectAndReport to be complete : %s\n", singleProfile->name);
735-
pthread_mutex_lock(&plMutex);
736-
initialized = false;
737-
T2Info("Sending signal to reuse Thread in CollectAndReportXconf\n");
738-
pthread_cond_signal(&reuseThread);
739-
pthread_mutex_unlock(&plMutex);
740-
pthread_join(singleProfile->reportThread, NULL);
741-
T2Info("reportThread exits and initialising the profile list\n");
742-
reportThreadExits = false;
743-
initialized = true;
744-
singleProfile->reportInProgress = false ;
737+
T2Info("Waiting for CollectAndReportXconf to be complete : %s\n", singleProfile->name);
745738
}
746739

747740
pthread_mutex_lock(&plMutex);
748741

742+
profile->reportThread = singleProfile->reportThread;
743+
749744
size_t count = Vector_Size(singleProfile->cachedReportList);
750745
// Copy any cached message present in previous single profile to new profile
751746
if(isNameEqual)
@@ -1013,9 +1008,14 @@ T2ERROR ProfileXConf_terminateReport()
10131008

10141009
T2ERROR ret = T2ERROR_FAILURE;
10151010

1011+
pthread_mutex_lock(&plMutex);
1012+
10161013
if(!singleProfile)
10171014
{
10181015
T2Error("Xconf profile is not set.\n");
1016+
1017+
pthread_mutex_unlock(&plMutex);
1018+
10191019
return ret;
10201020
}
10211021

@@ -1043,6 +1043,8 @@ T2ERROR ProfileXConf_terminateReport()
10431043
T2Info("No report generation in progress. No further action required for abort.\n");
10441044
}
10451045

1046+
pthread_mutex_unlock(&plMutex);
1047+
10461048
return ret;
10471049

10481050
}

0 commit comments

Comments
 (0)