Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
kevindiu authored and actions-user committed Jun 26, 2020
1 parent ecc9f5c commit 65ea3eb
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions internal/net/tcp/dialer.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,15 @@ type dialer struct {
}

type dialerCache struct {
ips []string
curIdx uint32
ips []string
cnt uint32
}

func (d *dialerCache) GetIP() string {
if atomic.LoadUint32(&d.curIdx) > math.MaxUint32-100 {
atomic.StoreUint32(&d.curIdx, 0)
if atomic.LoadUint32(&d.cnt) > math.MaxUint32-100 {
atomic.StoreUint32(&d.cnt, 0)
}
return d.ips[atomic.AddUint32(&d.curIdx, 1)%d.Len()]
return d.ips[atomic.AddUint32(&d.cnt, 1)%d.Len()]
}

func (d *dialerCache) Len() uint32 {
Expand Down Expand Up @@ -173,6 +173,10 @@ func (d *dialer) DialContext(ctx context.Context, network, address string) (net.

func (d *dialer) cachedDialer(dctx context.Context, network, addr string) (conn net.Conn, err error) {
host, port, err := net.SplitHostPort(addr)
if err != nil {
return nil, err
}

if dc, err := d.lookup(dctx, host); err == nil {
for i := uint32(0); i < dc.Len(); i++ {
if conn, err := d.dial(dctx, network, fmt.Sprintf("%s:%d", dc.GetIP(), port)); err == nil {
Expand Down

0 comments on commit 65ea3eb

Please sign in to comment.