Skip to content

Commit d2007fd

Browse files
xixu-mewwqgtxx
authored andcommitted
chore: improves thread safety in adapter
1 parent b5fa3ee commit d2007fd

1 file changed

Lines changed: 3 additions & 5 deletions

File tree

adapter/adapter.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -178,14 +178,12 @@ func (p *Proxy) URLTest(ctx context.Context, url string, expectedStatus utils.In
178178
p.history.Pop()
179179
}
180180

181-
state, ok := p.extra.Load(url)
182-
if !ok {
183-
state = &internalProxyState{
181+
state, _ := p.extra.LoadOrStoreFn(url, func() *internalProxyState {
182+
return &internalProxyState{
184183
history: queue.New[C.DelayHistory](defaultHistoriesNum),
185184
alive: atomic.NewBool(true),
186185
}
187-
p.extra.Store(url, state)
188-
}
186+
})
189187

190188
if !satisfied {
191189
record.Delay = 0

0 commit comments

Comments
 (0)