Skip to content

Commit 6fc14b4

Browse files
authored
Merge pull request #583 from xing-yang/fix_lock
Fix deadlock in recursive metric locks
2 parents 8de8be5 + 3c53046 commit 6fc14b4

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

pkg/metrics/metrics.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -231,15 +231,15 @@ func (opMgr *operationMetricsManager) RecordMetrics(opKey OperationKey, opStatus
231231
obj, exists := opMgr.cache[createKey]
232232
if exists {
233233
// record a cancel metric if found
234-
opMgr.recordCancelMetric(obj, createKey, operationDuration)
234+
opMgr.recordCancelMetricLocked(obj, createKey, operationDuration)
235235
}
236236

237237
// check if we have a CreateSnapshotAndReady operation pending for this
238238
createAndReadyKey := NewOperationKey(CreateSnapshotAndReadyOperationName, opKey.ResourceID)
239239
obj, exists = opMgr.cache[createAndReadyKey]
240240
if exists {
241241
// record a cancel metric if found
242-
opMgr.recordCancelMetric(obj, createAndReadyKey, operationDuration)
242+
opMgr.recordCancelMetricLocked(obj, createAndReadyKey, operationDuration)
243243
}
244244
}
245245

@@ -248,9 +248,8 @@ func (opMgr *operationMetricsManager) RecordMetrics(opKey OperationKey, opStatus
248248
}
249249

250250
// recordCancelMetric records a metric for a create operation that hasn't finished
251-
func (opMgr *operationMetricsManager) recordCancelMetric(val OperationValue, key OperationKey, duration float64) {
252-
opMgr.mu.Lock()
253-
defer opMgr.mu.Unlock()
251+
// This function must be called with opMgr mutex locked (to prevent recursive locks).
252+
func (opMgr *operationMetricsManager) recordCancelMetricLocked(val OperationValue, key OperationKey, duration float64) {
254253
// record a cancel metric if found
255254

256255
opMgr.opLatencyMetrics.WithLabelValues(

0 commit comments

Comments
 (0)