Browse Source

reverseproxy: Fix round robin data race (#4038)

master
Matthew Holt 4 years ago
parent
commit
ce5a0934a8
No known key found for this signature in database GPG Key ID: 2A349DD577D586A5
  1. 4
      modules/caddyhttp/reverseproxy/reverseproxy.go
  2. 4
      modules/caddyhttp/reverseproxy/selectionpolicies.go

4
modules/caddyhttp/reverseproxy/reverseproxy.go

@ -368,8 +368,8 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request, next caddyht
reqHost := r.Host
reqHeader := r.Header
defer func() {
r.Host = reqHost
r.Header = reqHeader
r.Host = reqHost // TODO: data race, see #4038
r.Header = reqHeader // TODO: data race, see #4038
}()
start := time.Now()

4
modules/caddyhttp/reverseproxy/selectionpolicies.go

@ -221,8 +221,8 @@ func (r *RoundRobinSelection) Select(pool UpstreamPool, _ *http.Request, _ http.
return nil
}
for i := uint32(0); i < n; i++ {
atomic.AddUint32(&r.robin, 1)
host := pool[r.robin%n]
robin := atomic.AddUint32(&r.robin, 1)
host := pool[robin%n]
if host.Available() {
return host
}

Loading…
Cancel
Save