From fda05d5d3d42b0f364c17418c654fa75406ebf44 Mon Sep 17 00:00:00 2001 From: nadoo <287492+nadoo@users.noreply.github.com> Date: Sat, 4 Apr 2020 00:03:47 +0800 Subject: [PATCH] strategy: try fwrdrs 1 by 1 when len(avail)==0 --- go.mod | 2 +- proxy/http/request.go | 1 - strategy/strategy.go | 4 ++-- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/go.mod b/go.mod index acf5d82..df9bd02 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/nadoo/glider -go 1.13 +go 1.14 require ( github.com/klauspost/cpuid v1.2.3 // indirect diff --git a/proxy/http/request.go b/proxy/http/request.go index be6ed34..f22a103 100644 --- a/proxy/http/request.go +++ b/proxy/http/request.go @@ -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 diff --git a/strategy/strategy.go b/strategy/strategy.go index 85152f2..512e2cb 100644 --- a/strategy/strategy.go +++ b/strategy/strategy.go @@ -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") } }