Skip to content

Commit d341612

Browse files
committed
add mutex
1 parent fd76e5a commit d341612

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

cni/telemetry/client/telemetry_client.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package telemetryclient
33
import (
44
"fmt"
55
"os"
6+
"sync"
67

78
"github.com/Azure/azure-container-networking/telemetry"
89
"go.uber.org/zap"
@@ -17,6 +18,7 @@ type TelemetryClient struct {
1718
CNIReportSettings *telemetry.CNIReport
1819
tb *telemetry.TelemetryBuffer
1920
logger *zap.Logger
21+
lock sync.Mutex
2022
}
2123

2224
var Telemetry = NewTelemetryClient(&telemetry.CNIReport{})
@@ -49,6 +51,8 @@ func (c *TelemetryClient) sendTelemetry(msg string) {
4951
if c.tb == nil {
5052
return
5153
}
54+
c.lock.Lock()
55+
defer c.lock.Unlock()
5256
c.CNIReportSettings.EventMessage = msg
5357
eventMsg := fmt.Sprintf("[%d] %s", os.Getpid(), msg)
5458
c.CNIReportSettings.EventMessage = eventMsg

0 commit comments

Comments
 (0)