Skip to content

Commit

Permalink
reverseproxy: Pointer receiver
Browse files Browse the repository at this point in the history
This avoids copying the Upstream, which has an atomically-accessed value
in it.
  • Loading branch information
mholt committed Jul 8, 2023
1 parent 66114cb commit 5dec11f
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions modules/caddyhttp/reverseproxy/hosts.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,10 @@ type Upstream struct {
unhealthy int32 // accessed atomically; status from active health checker
}

func (u Upstream) String() string {
return u.Dial
}
// (pointer receiver necessary to avoid a race condition, since
// copying the Upstream reads the 'unhealthy' field which is
// accessed atomically)
func (u *Upstream) String() string { return u.Dial }

// Available returns true if the remote host
// is available to receive requests. This is
Expand Down

0 comments on commit 5dec11f

Please sign in to comment.