strategy: try fwrdrs 1 by 1 when len(avail)==0

This commit is contained in:
nadoo 2020-04-04 00:03:47 +08:00
parent c4cebdd1d8
commit fda05d5d3d
3 changed files with 3 additions and 4 deletions

2
go.mod
View File

@ -1,6 +1,6 @@
module github.com/nadoo/glider
go 1.13
go 1.14
require (
github.com/klauspost/cpuid v1.2.3 // indirect

View File

@ -98,7 +98,6 @@ func parseRequest(r *bufio.Reader) (*request, error) {
req.ruri = u.String()
} else {
req.ruri = u.String()
base, err := url.Parse("http://" + header.Get("Host"))
if err != nil {
return nil, err

View File

@ -126,7 +126,7 @@ func (p *Proxy) NextForwarder(dstAddr string) *Forwarder {
defer p.mu.RUnlock()
if len(p.avail) == 0 {
return p.fwdrs[0]
return p.fwdrs[atomic.AddUint32(&p.index, 1)%uint32(len(p.fwdrs))]
}
return p.next(dstAddr)
@ -157,7 +157,7 @@ func (p *Proxy) init() {
if len(p.avail) == 0 {
// no available forwarders, set priority to 0 to check all forwarders in check func
p.SetPriority(0)
log.F("[strategy] no available forwarders, please check your config file or network settings", p.fwdrs[0].Addr())
log.F("[strategy] no available forwarders, please check your config file or network settings")
}
}