Skip to content

Commit 4aced25

Browse files
committed
fix race condition in metrics handler
Signed-off-by: Walther Lee <[email protected]>
1 parent 082aba2 commit 4aced25

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

pkg/metricshandler/metrics_handler.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,10 @@ func New(opts *options.Options, kubeClient kubernetes.Interface, storeBuilder ks
7272
// ReconfigureSharding reconfigures sharding with the current shard and totalShards, and
7373
// it's a no-op if both values are 0.
7474
func (m *MetricsHandler) ReconfigureSharding(ctx context.Context) {
75-
if m.curShard == 0 && m.curTotalShards == 0 {
75+
m.mtx.RLock()
76+
hasShardsSet := m.curShard != 0 || m.curTotalShards != 0
77+
m.mtx.RUnlock()
78+
if !hasShardsSet {
7679
return
7780
}
7881
m.ConfigureSharding(ctx, m.curShard, m.curTotalShards)

0 commit comments

Comments
 (0)