Skip to content

Commit f9898dc

Browse files
authored
Merge pull request #483 from i25959341/patch-1
Proxy accessing array in a not thread safe way
2 parents 6581387 + 7106b95 commit f9898dc

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

proxy/proxy.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@ type roundRobinSwitcher struct {
2929
}
3030

3131
func (r *roundRobinSwitcher) GetProxy(pr *http.Request) (*url.URL, error) {
32-
u := r.proxyURLs[r.index%uint32(len(r.proxyURLs))]
33-
atomic.AddUint32(&r.index, 1)
32+
index := atomic.AddUint32(&r.index, 1) - 1
33+
u := r.proxyURL[index%uint32(len(r.proxyURLs))]
34+
3435
ctx := context.WithValue(pr.Context(), colly.ProxyURLKey, u.String())
3536
*pr = *pr.WithContext(ctx)
3637
return u, nil

0 commit comments

Comments
 (0)