Skip to content

Commit 7b3748b

Browse files
authored
Merge pull request #2779 from jamescowens/fix_scraper_convergedstats_file_lock
scraper: Protect access to ConvergedStats.csv.gz with a lock
2 parents 92bf8af + 1f388c3 commit 7b3748b

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

src/gridcoin/scraper/scraper.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ CCriticalSection cs_ScraperGlobals;
6464
* file side.
6565
*/
6666
CCriticalSection cs_StructScraperFileManifest;
67+
/**
68+
* @brief Protects access to the ConvergedStats.csv.gz compressed statistics map output file.
69+
*/
70+
CCriticalSection cs_ConvergedStats;
6771
/**
6872
* @brief Protects the global converged scraper stats cache, which is populated by periodic runs of the scraper and/or
6973
* subscriber loop, and is used to validate superblocks.
@@ -3452,6 +3456,8 @@ bool StoreScraperFileManifest(const fs::path& file)
34523456

34533457
bool StoreStats(const fs::path& file, const ScraperStats& mScraperStats)
34543458
{
3459+
LOCK(cs_ConvergedStats);
3460+
34553461
if (fs::exists(file))
34563462
fs::remove(file);
34573463

@@ -6069,13 +6075,13 @@ UniValue testnewsb(const UniValue& params, bool fHelp)
60696075
{
60706076
LOCK(cs_ConvergedScraperStatsCache);
60716077

6072-
if (!ConvergedScraperStatsCache.NewFormatSuperblock.WellFormed())
6073-
{
6074-
UniValue error(UniValue::VOBJ);
6075-
error.pushKV("Error:", "Wait until a convergence is formed.");
6078+
if (!ConvergedScraperStatsCache.NewFormatSuperblock.WellFormed())
6079+
{
6080+
UniValue error(UniValue::VOBJ);
6081+
error.pushKV("Error:", "Wait until a convergence is formed.");
60766082

6077-
return error;
6078-
}
6083+
return error;
6084+
}
60796085

60806086
_log(logattribute::INFO, "testnewsb",
60816087
"Size of the PastConvergences map = " + ToString(ConvergedScraperStatsCache.PastConvergences.size()));

src/gridcoin/scraper/scraper.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
extern CCriticalSection cs_Scraper;
2828
extern CCriticalSection cs_ScraperGlobals;
2929
extern CCriticalSection cs_StructScraperFileManifest;
30+
extern CCriticalSection cs_ConvergedStats;
3031
extern CCriticalSection cs_ConvergedScraperStatsCache;
3132
extern CCriticalSection cs_TeamIDMap;
3233
extern CCriticalSection cs_VerifiedBeacons;

0 commit comments

Comments
 (0)