Skip to content

Commit 404e3ab

Browse files
authored
fix:修复map并发读写问题 (#1041)
1 parent 741398f commit 404e3ab

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

plugin/statis/base/apicall.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ func (a *ComponentStatics) run(ctx context.Context) {
104104
}
105105

106106
func (c *ComponentStatics) add(ac *APICall) {
107+
c.mutex.Lock()
108+
defer c.mutex.Unlock()
107109
index := fmt.Sprintf("%v-%v", ac.Api, ac.Code)
108110
item, exist := c.statis[index]
109111
if exist {
@@ -166,7 +168,10 @@ func (c *ComponentStatics) deal() {
166168
c.handler(c.t, startTime, nil)
167169
return
168170
}
171+
172+
c.mutex.Lock()
169173
defer func() {
174+
c.mutex.Unlock()
170175
passDuration := time.Since(startTime)
171176
if passDuration >= MaxLogWaitDuration {
172177
log.Warnf("[APICall]api static log duration %s, pass max %s", passDuration, MaxLogWaitDuration)

0 commit comments

Comments
 (0)