net.LookupIP may cause deadlock in windows
https://github.com/golang/go/issues/24178
This commit is contained in:
@ -492,7 +492,7 @@ func (s *HTTP) IsDeadLoop(inLocalAddr string, host string) bool {
|
||||
if *s.cfg.DNSAddress != "" {
|
||||
outIPs = []net.IP{net.ParseIP(s.Resolve(outDomain))}
|
||||
} else {
|
||||
outIPs, err = net.LookupIP(outDomain)
|
||||
outIPs, err = utils.MyLookupIP(outDomain)
|
||||
}
|
||||
if err == nil {
|
||||
for _, ip := range outIPs {
|
||||
|
||||
@ -598,7 +598,7 @@ func (s *Socks) IsDeadLoop(inLocalAddr string, host string) bool {
|
||||
if *s.cfg.DNSAddress != "" {
|
||||
outIPs = []net.IP{net.ParseIP(s.Resolve(outDomain))}
|
||||
} else {
|
||||
outIPs, err = net.LookupIP(outDomain)
|
||||
outIPs, err = utils.MyLookupIP(outDomain)
|
||||
}
|
||||
if err == nil {
|
||||
for _, ip := range outIPs {
|
||||
|
||||
@ -29,6 +29,8 @@ import (
|
||||
"github.com/snail007/goproxy/utils/id"
|
||||
|
||||
kcp "github.com/xtaci/kcp-go"
|
||||
|
||||
"context"
|
||||
)
|
||||
|
||||
func IoBind(dst io.ReadWriteCloser, src io.ReadWriteCloser, fn func(err interface{}), log *logger.Logger) {
|
||||
@ -497,7 +499,7 @@ func IsIternalIP(domainOrIP string, always bool) bool {
|
||||
}
|
||||
|
||||
if isDomain {
|
||||
outIPs, err = net.LookupIP(domainOrIP)
|
||||
outIPs, err = MyLookupIP(domainOrIP)
|
||||
} else {
|
||||
outIPs = []net.IP{net.ParseIP(domainOrIP)}
|
||||
}
|
||||
@ -632,3 +634,28 @@ func InsertProxyHeaders(head []byte, headers string) []byte {
|
||||
// }
|
||||
// return
|
||||
// }
|
||||
|
||||
|
||||
/*
|
||||
net.LookupIP may cause deadlock in windows
|
||||
https://github.com/golang/go/issues/24178
|
||||
|
||||
*/
|
||||
|
||||
func MyLookupIP(host string) ([]net.IP, error) {
|
||||
|
||||
ctx ,cancel := context.WithTimeout(context.Background(),time.Second *time.Duration(3))
|
||||
defer func() {
|
||||
cancel()
|
||||
//ctx.Done()
|
||||
}()
|
||||
addrs, err := net.DefaultResolver.LookupIPAddr(ctx, host)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ips := make([]net.IP, len(addrs))
|
||||
for i, ia := range addrs {
|
||||
ips[i] = ia.IP
|
||||
}
|
||||
return ips, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user