FlowerWrong / tun2socks

Redirect tun flow to socks 5 in golang, support tcp and udp.
420 stars 108 forks source link

错误 socket: too many open files #32

Closed Archieeeeee closed 5 years ago

Archieeeeee commented 6 years ago

添加IP地址1.1.1.1到路由,使用该IP地址解析DNS,连续解析

!/bin/bash

for i in $(seq 1 100); do echo $(host www.bing.com 1.1.1.1) done

就会有报错日志

2018/06/15 18:00:04 proxies.go:62: [proxies] default proxy: "B" 2018/06/15 18:00:04 tun_linux.go:29: [tun] interface name is tun1 2018/06/15 18:00:04 cmd.go:14: [command] ifconfig tun1 26.26.26.1 netmask 255.255.255.0 2018/06/15 18:00:04 cmd.go:14: [command] route add -net 198.18.0.0/15 dev tun1 2018/06/15 18:00:04 cmd.go:14: [command] route add -net 91.108.4.0/22 dev tun1 2018/06/15 18:00:04 cmd.go:14: [command] route add -net 91.108.56.0/22 dev tun1 2018/06/15 18:00:04 cmd.go:14: [command] route add -net 109.239.140.0/24 dev tun1 2018/06/15 18:00:04 cmd.go:14: [command] route add -net 149.154.160.0/20 dev tun1 2018/06/15 18:00:04 cmd.go:14: [command] route add -net 149.154.167.0/24 dev tun1 2018/06/15 18:00:04 cmd.go:14: [command] route add -host 1.1.1.1 dev tun1 2018/06/15 18:00:04 cmd.go:14: [command] route add -host 4.4.4.4 dev tun1 2018/06/15 18:00:04 cmd.go:14: [command] route add -net 69.162.69.0/24 dev tun1 2018/06/15 18:00:04 main.go:95: [app] run tun2socks(0.50) success 2018/06/15 18:01:36 udp2socks5.go:87: [error] Fail to connect SOCKS proxy dial tcp 127.0.0.1:53008: socket: too many open files 2018/06/15 18:01:36 udp.go:72: [error] NewUDPTunnel failed dial tcp 127.0.0.1:53008: socket: too many open files 2018/06/15 18:01:41 udp2socks5.go:87: [error] Fail to connect SOCKS proxy dial tcp 127.0.0.1:53008: socket: too many open files 2018/06/15 18:01:41 udp.go:72: [error] NewUDPTunnel failed dial tcp 127.0.0.1:53008: socket: too many open files 2018/06/15 18:01:46 udp2socks5.go:87: [error] Fail to connect SOCKS proxy dial tcp 127.0.0.1:53008: socket: too many open files 2018/06/15 18:01:46 udp.go:72: [error] NewUDPTunnel failed dial tcp 127.0.0.1:53008: socket: too many open files 2018/06/15 18:01:51 udp2socks5.go:87: [error] Fail to connect SOCKS proxy dial tcp 127.0.0.1:53008: socket: too many open files 2018/06/15 18:01:51 udp.go:72: [error] NewUDPTunnel failed dial tcp 127.0.0.1:53008: socket: too many open files

netstat -lnp 可以看到来自socks5进程的很多未关闭的UDP连接,所以导致了上诉错误吗,问题是哪个过程没有及时关闭这些udp连接呢

FlowerWrong commented 6 years ago

我试了下,我这里不会报这个问题。我的ulimit修改过。

ulimit -a

-t: cpu time (seconds)              unlimited
-f: file size (blocks)              unlimited
-d: data seg size (kbytes)          unlimited
-s: stack size (kbytes)             8192
-c: core file size (blocks)         0
-v: address space (kbytes)          unlimited
-l: locked-in-memory size (kbytes)  unlimited
-u: processes                       2048
-n: file descriptors                65535
Archieeeeee commented 6 years ago

不走路由的话,DNS查询完毕UDP连接也立即关闭了,原因还是UDP没有及时关闭导致的,修改ulimit可以改善,但是没有解决。

FlowerWrong commented 5 years ago

加了一下针对dns查询的优化

https://github.com/FlowerWrong/tun2socks/blob/master/tun2socks/udp2socks5.go#L228-L232

FlowerWrong commented 5 years ago

@Archieeeeee 麻烦再次测试一下。