coyove / goflyway

An encrypted HTTP server
MIT License
4.31k stars 654 forks source link

(arm version) DNS lookup failed: read udp: read: connection refused #126

Closed binus closed 5 years ago

binus commented 5 years ago

version fa7eda0, with ignore_local_dns ON go build arm version cmd: ./gof -up="cf://$$:80" -k="$$" -l=":8100" -web-port="8101" -lv=dbg -g -U=http firefox -> SwitchyOmega -> gof:socks5 Errror only occurs in arm version. Linux x86 and windows are all good.

UTC,main.go:266, INFO ,goflyway devel main.go:277, WARNING ,Failed to read ACL config: open chinalist.txt: no such file or directory main.go:435, INFO ,Upstream config: cf://$$:80 main.go:308, INFO ,Global proxy enabled main.go:415, INFO ,Client fb16884 started: you->0.0.0.0:8100->cloudflare->$$:80 main.go:411, INFO ,Web console started at 127.0.0.1:8101 acl.go:42, INFO ,ACL check result: unknown >> 7 ## I added acl.go:42 to print the debug info acl.go:43, ERROR ,ACL check error: DNS lookup failed: lookup google.com on [::1]:53: read udp [::1]:39998->[::1]:53: read: connection refused ## this is the original acl.go:42 debug print client.go:538, LOG ,Global - google.com:80 client.go:541, ERROR ,"Dial failed: dial, lookup $$ on [::1]:53: read udp [::1]:38258->[::1]:53: read: connection refused" ......

Is it because of the -g option or ignore_dns flag? Thanks for any clue about this.

binus commented 5 years ago

Seems at least we need to do one dns resolve locally, to resolve the upstream cloudfare domain! maybe the net.ResolveIPAddr doesn't works well in arm :(

binus commented 5 years ago

Solved: net.ResolveIPAddr in arm may query local dns server ( [::1]:53 ), but missing. Set up manually and all goes well. BTW: thanks for your useful logg debug tool, which help me alot.

binus commented 5 years ago

More info: https://github.com/golang/go/issues/10714 https://github.com/golang/go/issues/8877 https://github.com/golang/go/issues/24393 https://stackoverflow.com/questions/38959067/dns-lookup-issue-when-running-my-go-app-in-termux

Fix method 1: set up local dns server and listen udp:53 , need root. Fix method 2: hack go/net to dial higher udp port for dns resolve, to avoid root privilege. Fix method 3: use cgo way. Fix method 4: use pure go way but change default/fallback behavior. Fix method 5: wait for ʕ ◔ϖ◔ʔ (golang) solving this problem ...

EOF

coyove commented 5 years ago

Using cgo is okay to me, otherwise we will have to use some 3rd libs like miekg/dns

cs8425 commented 5 years ago

I use some hack & reflect to overwrite defaultNS in net package. And just work!!

Only test with go version go1.11.5 linux/amd64, Build with GOOS=linux GOARCH=arm GOARM=7 and GOOS=linux GOARCH=arm64, On a Android 6.0, kernel 3.10.49, aarch64 CPU phone.

The code: https://gist.github.com/cs8425/107e01a0652f1f1f6e033b5b68364b5e