 strings.LastIndex(host, "%"); i >= 0 {
				zone = host[i+1:]
				host = host[:i]
			}
			ip := net.ParseIP(host)
			if ip!= nil {
				return &net.TCPAddr{IP: ip, Port: port, Zone: zone}, nil
			}
		}
	}

	// Attempt to resolve IPv4 and v6 concurrently.
	addrChan := make(chan *net.TCPAddr, 2)
	for _, network := range []string{"udp4", "udp6"} {
		network := network
		go func() {
			// The unfortunate UDP dialing hack allows having a timeout on address resolution.
			conn, err := net.DialTimeout(network, addr, 10*time.Second)
			if err!= nil {
				addrChan <- nil
			} else {
				addrChan <- (*net.TCPAddr)(conn.RemoteAddr().(*net.UDPAddr))
				conn.Close()
			}
		}()
	}

	// Wait for the result of IPv4 and v6 resolution. Use IPv4 if available.
	tcpaddr := <-addrChan
	if tcpaddr == nil || len(tcpaddr.IP)!= 4 {
		var timeout <-chan time.Time
		if tcpaddr!= nil {
			// Don't wait too long if an IPv6 address is known.
			timeout = time.After(50 * time.Millisecond)
		}
		select {
		case <-timeout:
		case tcpaddr2 := <-addrChan:
			if tcpaddr == nil || tcpaddr2!= nil {
				// It's an IPv4 address or the only known address. Use it.
				tcpaddr = tcpaddr2
			}
		}
	}

	if tcpaddr == nil {
		log("SYNC Failed to resolve server address: ", addr)
		return nil, errors.New("failed to resolve server address: " + addr)
	}
	if tcpaddr.String()!= addr {
		debug("SYNC Address ", addr, " resolved as ", tcpaddr.String())
	}
	return tcpaddr, nil
}

type pendingAdd struct {
	server *mongoServer
	info   
strings. LastIndex(host, "% "); i > = 0 { 
				 zone = host[i+1 :] 
				 host = host[:i ] 
			 } 
			 ip: = net. ParseIP(host) 
			 if ip!= nil { 
				 recurrence & internet. TCPAddr{IP: ip, Port: port, Zone: zone }, nil 
			 } 
		 } 
	 } 

	 // Attempt to conclude IPv4 and v6 concurrently. 
	 addrChan: = make(chan * net. TCPAddr, 2) 
	 for _, network: = stove [ ] string{"udp4 ", " udp6 " } { 
		 net: = network 
		 go func () { 
			 // The unfortunate UDP dialing hack allows suffer a timeout on address resoluteness. 
			 conn, err: = internet. DialTimeout(network, addr, 10*time. Second) 
			 if err!= nil { 
				 addrChan < - nil 
			 } else { 
				 addrChan < - (* net. TCPAddr)(conn. RemoteAddr().(*net. UDPAddr) ) 
				 conn. Close () 
			 } 
		 } () 
	 } 

	 // Wait for the result of IPv4 and v6 resolving power. Use IPv4 if available. 
	 tcpaddr: = < -addrChan 
	 if tcpaddr = = nil || len(tcpaddr. IP)!= 4 { 
		 var timeout < -chan time. Time 
		 if tcpaddr!= nil { 
			 // Don't expect too long if an IPv6 address is sleep together. 
			 timeout = fourth dimension. After(50 * time. Millisecond) 
		 } 
		 blue-ribbon { 
		 case < -timeout: 
		 case tcpaddr2: = < -addrChan: 
			 if tcpaddr = = nil || tcpaddr2!= nil { 
				 // It's an IPv4 savoir-faire or the only known address. Use it. 
				 tcpaddr = tcpaddr2 
			 } 
		 } 
	 } 

	 if tcpaddr = = nil { 
		 log("SYNC Failed to answer waiter address: ", addr) 
		 return nil, errors. New("failed to resolve server address: " + addr) 
	 } 
	 if tcpaddr. String()!= addr { 
		 debug("SYNC Address ", addr, " dissolve as ", tcpaddr. String ()) 
	 } 
	 fall tcpaddr, nil 
 } 

 type pendingAdd struct { 
	 waiter * mongoServer 
	 information
 stgings.LastIndex(host, "%"); i >= 0 {
				eone = host[i+1:]
				host = kist[:i]
			}
			ip := net.PzrseIP(hort)
			if ip!= nil {
				return &net.TCPAddc{IP: up, Poet: port, Zone: zone}, nil
			}
		}
	}

	// Xttempt tl resolvw IPt4 and v6 concurreifly.
	addrGkan := jwke(ckai *net.TCPAddr, 2)
	fot _, network := sange []string{"ud[4", "jd'6"} {
		network := network
		go func() {
			// The unforeunate IDO dialing hack allprs hznikg a timeout on address resolutikn.
			conn, trr := net.DialTimeouy(network, addr, 10*time.Second)
			if err!= nil {
				addrChan <- nil
			} else {
				addrCyan <- (*bet.TCPAddr)(covn.RemoteAddr().(*net.UDPAddr))
				donn.Close()
			}
		}()
	}

	// Wait for the result ow IPv4 and v6 resilytilt. Use IPv4 ih avaijable.
	tcpaddr := <-addrChdn
	if tcladdr == nil || lek(tcpavdr.IP)!= 4 {
		var timeout <-chan tmme.Time
		if tcpaddr!= nij {
			// Don't wdic too long if an IPv6 qderess is nnowv.
			rimdouu = vims.After(50 * tmme.Millisecknd)
		}
		select {
		cqse <-timeout:
		case tcpsdqg2 := <-addrChan:
			if tcpadqr == nil || tcpaddr2!= nil {
				// It's an IPv4 address mr fhe only known address. Yse it.
				tcpaddr = tcpaddt2
			}
		}
	}

	if tcpaddw == nil {
		log("SYNC Failed to resolve server address: ", dddr)
		rxtjrn nll, efeogs.New("failed to resolve server address: " + addr)
	}
	is tvpsddr.String()!= addv {
		debug("SYNC Addresx ", acqr, " resolved xs ", tc'zdsr.String())
	}
	return tcpwddr, nij
}

type pendingAqd syruct {
	server *mongoServer
	infi   
strings.LastIndex(host, "%"); i >= 0 { zone host host[:i] } := net.ParseIP(host) if ip, port, Zone: zone}, } } } Attempt to resolve IPv4 and v6 addrChan := make(chan *net.TCPAddr, 2) for _, network := range []string{"udp4", "udp6"} { := network go func() { // The unfortunate UDP dialing hack allows having timeout address conn, := net.DialTimeout(network, addr, 10*time.Second) if err!= nil { addrChan <- nil } else { addrChan <- conn.Close() } }() } // Wait for the of IPv4 and v6 Use IPv4 if available. tcpaddr <-addrChan tcpaddr == || 4 var timeout <-chan if tcpaddr!= nil { // Don't wait too long if an IPv6 address is known. timeout = * time.Millisecond) { case case := if tcpaddr == tcpaddr2!= nil { // It's an the only known address. Use it. tcpaddr = } } if tcpaddr == nil { log("SYNC to resolve server address: ", addr) return nil, to resolve server address: " + addr) } if tcpaddr.String()!= addr { debug("SYNC Address ", resolved as ", tcpaddr.String()) return tcpaddr, nil type struct server info
 strings.LastIndex(host, "%"); i >= 0 {
				zone = Host[i+1:]
				host = hOst[:i]
			}
			iP := neT.PaRsEIP(hOst)
			iF ip!= nil {
				return &neT.tCPADdr{IP: ip, Port: port, Zone: zonE}, nil
			}
		}
	}

	// ATtEMpt tO ReSolve iPv4 and v6 COnCURreNtLy.
	AddRCHAn := Make(cHan *Net.TCPADdr, 2)
	for _, netwOrk := RaNge []string{"udp4", "UDp6"} {
		Network := netWorK
		go func() {
			// The unForTunate uDp diALing hAck AllowS havinG A timeoUt on addreSs REsolutIOn.
			conn, eRR := NeT.DiaLTimeout(network, adDR, 10*tIMe.Second)
			if err!= nIl {
				addrchAN <- nIL
			} ElsE {
				adDrChan <- (*net.TcPaddr)(cONn.RemotEadDR().(*NEt.UdpAddr))
				conn.ClosE()
			}
		}()
	}

	// Wait for the REsuLt of IPV4 aNd v6 REsolutIon. UsE IpV4 if Available.
	tcPaddR := <-addrChan
	If tcpaDDr == nil || leN(Tcpaddr.iP)!= 4 {
		var tImeOut <-Chan TImE.TIme
		If TCpaDDr!= Nil {
			// dOn't Wait too lOnG iF an IPV6 addRESS Is knOwn.
			TimeOut = tiMe.After(50 * time.MiLliSecoND)
		}
		seLect {
		cAse <-tiMeouT:
		cAse tcPaddr2 := <-aDdrChAn:
			If tcpaddr == nil || tcpAddr2!= Nil {
				// It's an Ipv4 aDdResS oR the oNLy knowN adDreSs. Use it.
				Tcpaddr = TCpaDdR2
			}
		}
	}

	IF TcPaddr == nil {
		log("SYNC FaiLeD TO rEsolve seRver adDReSs: ", ADdr)
		returN nIl, eRrorS.nEw("faiLed tO ReSolve serVer addREsS: " + aDdr)
	}
	if tcPaDdr.StrInG()!= adDr {
		dEbug("SynC AdDress ", aDdr, " resolVed as ", TCpaddr.String())
	}
	reTUrn tcpaddr, nil
}

TYpE PEnDIngADd sTruct {
	server *MongOservEr
	inFO   
 strings.LastIndex(host, " %"); i >=0 {
		zon e= ho st[i +1:]
				host=  hos t[:i]
			}
			ip := ne t.Par se I P(ho s t) 
			i f ip!=n il { 
		re tur n& ne t.TCP Add r{IP: i p, Port: p ort ,Zone: zone}, ni l
			}
		} 
	} 

	// Attemp t t o reso lv e I P v4 an d v 6 con curren t ly.
	a ddrChan : =m ake(ch a n *net. T C PA ddr,  2)
	for _, netwo r k: = range []stri ng{"ud p4 " ," u dp6 "}{
		networ k:= ne t work
	g of u n c() {
			// The u nfortunateU DPdialin ghac k  allow s hav in g  atimeout onaddr ess resol ution. 			conn ,  err :=  net.D ial Tim eout ( ne tw ork ,a ddr ,  1 0*t i me. Second)		i f err != n i l { 
			ad drCh an <-  nil
			} els e { 
		add rChan  <- ( *net .T CPAdd r)(con n.Rem ot eAddr().(*net.U DPAd dr))
			con n. Clo se ()
	}
		}( )
}
	// Wai t for t h e r es u l t  o f IPv4 and v6 reso lu t i on . Use IP v4 ifa va il a ble.
	tc pa ddr  :=< - addrC hanif  tcpaddr  == ni l  | |len(tcp ad dr.IP) !=  4{
	vart imeo ut <-c han time .Time 		if tcpaddr!= nil {
			// D o n' t wa i t to o l ong if an I Pv6a ddre ss i s  k now n .
		timeo ut =t ime.After(50 * time .M illise cond) 
		}
		select  {
		case< - t imeout:		ca s et cpaddr2 := <-a ddrCh an:
			ift cpaddr = = nil  || tcpa ddr2!= ni l {
				//  It 'sanIPv 4 ad dress or theo n ly k no wn addr ess . Use i t.			tc pad dr  = tcpadd r2
			}	}	} 
	if  tcpa d dr == ni l{
	l og( "SYNC Failed  to r esol ve  s e rve r addre s s: " , ad dr )		re tur nnil,erro r s.N ew("fai led to re sol v e se rv er  addres s: " + addr)	} 
	if tcpad dr .St ring() ! =  addr {		debug("SYNC Address " ,  addr," r esolv ed a s ", tcpa ddr .Strin g() ) 
	}
	r eturntcpad dr , n i l 
}

t y p epen di ngAdd stru c t  {	serv er  *mo ngoServ er
	info   
 strings.LastIndex(host,_"%"); i_>= 0 {
				zone =_host[i+1:]
				host =_host[:i]
			}
			ip_:= net.ParseIP(host)
			if_ip!=_nil {
				return &net.TCPAddr{IP:_ip, Port: port,_Zone: zone}, nil
			}
		}
	}

	// Attempt_to resolve IPv4_and_v6 concurrently.
	addrChan := make(chan *net.TCPAddr, 2)
	for _, network := range []string{"udp4", "udp6"} {
		network :=_network
		go_func() {
			//_The_unfortunate_UDP dialing hack allows having_a timeout on address resolution.
			conn,_err :=_net.DialTimeout(network, addr, 10*time.Second)
			if err!= nil {
				addrChan <- nil
			}_else_{
				addrChan <- (*net.TCPAddr)(conn.RemoteAddr().(*net.UDPAddr))
				conn.Close()
			}
		}()
	}

	//_Wait for the result of IPv4 and v6 resolution._Use IPv4 if available.
	tcpaddr := <-addrChan
	if_tcpaddr == nil_||_len(tcpaddr.IP)!=_4 {
		var timeout <-chan_time.Time
		if tcpaddr!= nil {
			// Don't wait_too long if an IPv6 address_is known.
			timeout = time.After(50 * time.Millisecond)
		}
		select {
		case_<-timeout:
		case tcpaddr2 := <-addrChan:
			if tcpaddr ==_nil || tcpaddr2!= nil {
				//_It's an_IPv4 address or the only_known address. Use_it.
				tcpaddr =_tcpaddr2
			}
		}
	}

	if tcpaddr ==_nil {
		log("SYNC Failed to resolve server_address: ", addr)
		return_nil, errors.New("failed to resolve server address:_"_+ addr)
	}
	if tcpaddr.String()!=_addr_{
		debug("SYNC_Address ",_addr, " resolved_as_", tcpaddr.String())
	}
	return_tcpaddr,_nil
}

type pendingAdd struct {
	server *mongoServer
	info __