Skip to content

Commit

Permalink
fix race condition in metrics handler
Browse files Browse the repository at this point in the history
Signed-off-by: Walther Lee <[email protected]>
  • Loading branch information
wallee94 committed Sep 5, 2024
1 parent 082aba2 commit 4aced25
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion pkg/metricshandler/metrics_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,10 @@ func New(opts *options.Options, kubeClient kubernetes.Interface, storeBuilder ks
// ReconfigureSharding reconfigures sharding with the current shard and totalShards, and
// it's a no-op if both values are 0.
func (m *MetricsHandler) ReconfigureSharding(ctx context.Context) {
if m.curShard == 0 && m.curTotalShards == 0 {
m.mtx.RLock()
hasShardsSet := m.curShard != 0 || m.curTotalShards != 0
m.mtx.RUnlock()
if !hasShardsSet {
return
}
m.ConfigureSharding(ctx, m.curShard, m.curTotalShards)
Expand Down

0 comments on commit 4aced25

Please sign in to comment.