Skip to content

Commit

Permalink
[WIP] statistics: fix crash when creating a series stat
Browse files Browse the repository at this point in the history
Under normal circumstances, when a statistic is updated, we first search
whether it exists, and if not, we add it to the statistics hash.
However, due to the way it is implemented, searching and adding a
statistic is not atomic, hence, with high concurrency, when adding a new
statistic, we might already find an existing one there. In this case,
the code tries to return that statistic in the `pvar` parameter -
however, that parameter might be a (r/o) function, hence a crash
happens. This commit fixes the crash. Close #3136

However, it returns 0, as if the statistic was properly added - the
problem with this approach is that from the caller's perspective, we do
not know whether the statistic was already there or not, to free the
existing structure - hence this might result into a leak. We are still
working on a solution for this.

(cherry picked from commit 4640465)
  • Loading branch information
razvancrainea committed Sep 27, 2023
1 parent ca968c2 commit e031651
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion statistics.c
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,8 @@ static int __register_stat(str *module, str *name, stat_var **pvar,
shm_free(stat);
}

*pvar = it;
if ((flags&STAT_IS_FUNC)==0)
*pvar = it;
return 0;
}
}
Expand Down

0 comments on commit e031651

Please sign in to comment.