xjasonlyu / tun2socks

tun2socks - powered by gVisor TCP/IP stack
https://github.com/xjasonlyu/tun2socks/wiki
GNU General Public License v3.0
2.85k stars 404 forks source link

[Bug] connect to 127.0.0.1:10801: dial tcp 127.0.0.1:10801: socket: too many open files #267

Closed khayyamov closed 8 months ago

khayyamov commented 1 year ago

Verify steps

Version

2.5.1

What OS are you seeing the problem on?

macOS

Description

I run tun2socks like this CLI below And I run xray-core with a correct configuration, but this warning is printed as soon as it is run

CLI or Config

sudo ./tun2socks -device utun123 -proxy socks5://127.0.0.1:10801 -interface en0

sudo ifconfig utun123 198.18.0.1 198.18.0.1 up && sudo route add -net 1.0.0.0/8 198.18.0.1 &&
sudo route add -net 2.0.0.0/7 198.18.0.1 &&
sudo route add -net 4.0.0.0/6 198.18.0.1 &&
sudo route add -net 8.0.0.0/5 198.18.0.1 &&
sudo route add -net 16.0.0.0/4 198.18.0.1 &&
sudo route add -net 32.0.0.0/3 198.18.0.1 &&
sudo route add -net 64.0.0.0/2 198.18.0.1 &&
sudo route add -net 128.0.0.0/1 198.18.0.1 &&
sudo route add -net 198.18.0.0/15 198.18.0.1

Logs

‍‍
INFO[0073] [UDP] 198.18.0.1:51717 <-> 178.22.122.100:53 
INFO[0073] [UDP] 198.18.0.1:57894 <-> 178.22.122.100:53 
INFO[0073] [UDP] 198.18.0.1:62676 <-> 178.22.122.100:53 
INFO[0073] [UDP] 198.18.0.1:57653 <-> 178.22.122.100:53 
INFO[0073] [UDP] 198.18.0.1:52786 <-> 178.22.122.100:53 
INFO[0073] [UDP] 198.18.0.1:65466 <-> 178.22.122.100:53 
INFO[0073] [UDP] 198.18.0.1:58167 <-> 178.22.122.100:53 
INFO[0073] [UDP] 198.18.0.1:65259 <-> 178.22.122.100:53 
INFO[0073] [UDP] 198.18.0.1:53499 <-> 178.22.122.100:53 
INFO[0073] [UDP] 198.18.0.1:50636 <-> 178.22.122.100:53 
INFO[0073] [UDP] 198.18.0.1:64732 <-> 178.22.122.100:53 
INFO[0073] [UDP] 198.18.0.1:59060 <-> 178.22.122.100:53 
INFO[0073] [UDP] 198.18.0.1:51560 <-> 178.22.122.100:53 
INFO[0073] [UDP] 198.18.0.1:51268 <-> 178.22.122.100:53 
WARN[0073] [UDP] dial 178.22.122.100:53: client handshake: EOF 
INFO[0073] [UDP] 198.18.0.1:49311 <-> 178.22.122.100:53 
WARN[0073] [UDP] dial 178.22.122.100:53: connect to 127.0.0.1:10801: dial tcp 127.0.0.1:10801: socket: too many open files 
WARN[0074] [UDP] dial 178.22.122.100:53: connect to 127.0.0.1:10801: dial tcp 127.0.0.1:10801: socket: too many open files 
WARN[0074] [UDP] dial 178.22.122.100:53: connect to 127.0.0.1:10801: dial tcp 127.0.0.1:10801: socket: too many open files 
WARN[0074] [UDP] dial 178.22.122.100:53: connect to 127.0.0.1:10801: dial tcp 127.0.0.1:10801: socket: too many open files 
WARN[0075] [UDP] dial 185.51.200.2:53: connect to 127.0.0.1:10801: dial tcp 127.0.0.1:10801: socket: too many open files 
WARN[0075] [UDP] dial 185.51.200.2:53: connect to 127.0.0.1:10801: dial tcp 127.0.0.1:10801: socket: too many open files 
WARN[0075] [UDP] dial 185.51.200.2:53: connect to 127.0.0.1:10801: dial tcp 127.0.0.1:10801: socket: too many open files 
WARN[0075] [UDP] dial 185.51.200.2:53: connect to 127.0.0.1:10801: dial tcp 127.0.0.1:10801: socket: too many open files 
WARN[0075] [UDP] dial 185.51.200.2:53: connect to 127.0.0.1:10801: dial tcp 127.0.0.1:10801: socket: too many open files 


### How to Reproduce

1. Add Specific Route
2. run tun2socks 
3. run xraycore
xjasonlyu commented 1 year ago

If your xray server didn’t bind to a specific interface (en0 in this example), it will cause too many open files issue like this one due to routing loop.

khayyamov commented 1 year ago

That means I have to put en0 address instead of 127.0.0.1

khayyamov commented 1 year ago

"inbounds": [ { "listen": "127.0.0.1", "port": 51836, "protocol": "socks", "settings": { "auth": "noauth", "udp": true, "allowTransparent": true }, "sniffing": { "destOverride": [ "http", "tls" ], "enabled": true, "metadataOnly": null, "routeOnly": false }, "tag": "socks" } ] this is my xray inbound socks

xjasonlyu commented 1 year ago

I think xray has interface bound supports like v2ray does, but I’m not sure. 🤔

khayyamov commented 1 year ago

sudo ./tun32 -device utun123 -proxy socks5://127.0.0.1:10801 -interface en0 INFO[0000] [DIALER] bind to interface: en0
INFO[0000] [STACK] tun://utun123 <-> socks5://127.0.0.1:10801 WARN[0019] [UDP] dial 178.22.122.100:53: connect to 127.0.0.1:10801: dial tcp 127.0.0.1:10801: connect: connection refused

I received new issue when i change listen=::1 /: { "inbounds": [ { "listen": "::1", "port": 10801, "protocol": "socks", "settings": { "auth": "noauth", "udp": true, "allowTransparent": true }, "sniffing": { "destOverride": [ "http", "tls" ], "enabled": true, "metadataOnly": null, "routeOnly": false }, "tag": "socks" } ]

sonvirgo commented 11 months ago

Verify steps

* [x]  Is this something you can **debug and fix**? Send a pull request! Bug fixes and documentation fixes are welcome.

* [x]  I have searched on the [issue tracker](%E2%80%A6%E2%80%A6/) for a related issue.

Version

2.5.1

What OS are you seeing the problem on?

macOS

Description

I run tun2socks like this CLI below And I run xray-core with a correct configuration, but this warning is printed as soon as it is run

CLI or Config

sudo ./tun2socks -device utun123 -proxy socks5://127.0.0.1:10801 -interface en0

sudo ifconfig utun123 198.18.0.1 198.18.0.1 up && sudo route add -net 1.0.0.0/8 198.18.0.1 &&
sudo route add -net 2.0.0.0/7 198.18.0.1 &&
sudo route add -net 4.0.0.0/6 198.18.0.1 &&
sudo route add -net 8.0.0.0/5 198.18.0.1 &&
sudo route add -net 16.0.0.0/4 198.18.0.1 &&
sudo route add -net 32.0.0.0/3 198.18.0.1 &&
sudo route add -net 64.0.0.0/2 198.18.0.1 &&
sudo route add -net 128.0.0.0/1 198.18.0.1 &&
sudo route add -net 198.18.0.0/15 198.18.0.1

Logs

‍‍
INFO[0073] [UDP] 198.18.0.1:51717 <-> 178.22.122.100:53 
INFO[0073] [UDP] 198.18.0.1:57894 <-> 178.22.122.100:53 
INFO[0073] [UDP] 198.18.0.1:62676 <-> 178.22.122.100:53 
INFO[0073] [UDP] 198.18.0.1:57653 <-> 178.22.122.100:53 
INFO[0073] [UDP] 198.18.0.1:52786 <-> 178.22.122.100:53 
INFO[0073] [UDP] 198.18.0.1:65466 <-> 178.22.122.100:53 
INFO[0073] [UDP] 198.18.0.1:58167 <-> 178.22.122.100:53 
INFO[0073] [UDP] 198.18.0.1:65259 <-> 178.22.122.100:53 
INFO[0073] [UDP] 198.18.0.1:53499 <-> 178.22.122.100:53 
INFO[0073] [UDP] 198.18.0.1:50636 <-> 178.22.122.100:53 
INFO[0073] [UDP] 198.18.0.1:64732 <-> 178.22.122.100:53 
INFO[0073] [UDP] 198.18.0.1:59060 <-> 178.22.122.100:53 
INFO[0073] [UDP] 198.18.0.1:51560 <-> 178.22.122.100:53 
INFO[0073] [UDP] 198.18.0.1:51268 <-> 178.22.122.100:53 
WARN[0073] [UDP] dial 178.22.122.100:53: client handshake: EOF 
INFO[0073] [UDP] 198.18.0.1:49311 <-> 178.22.122.100:53 
WARN[0073] [UDP] dial 178.22.122.100:53: connect to 127.0.0.1:10801: dial tcp 127.0.0.1:10801: socket: too many open files 
WARN[0074] [UDP] dial 178.22.122.100:53: connect to 127.0.0.1:10801: dial tcp 127.0.0.1:10801: socket: too many open files 
WARN[0074] [UDP] dial 178.22.122.100:53: connect to 127.0.0.1:10801: dial tcp 127.0.0.1:10801: socket: too many open files 
WARN[0074] [UDP] dial 178.22.122.100:53: connect to 127.0.0.1:10801: dial tcp 127.0.0.1:10801: socket: too many open files 
WARN[0075] [UDP] dial 185.51.200.2:53: connect to 127.0.0.1:10801: dial tcp 127.0.0.1:10801: socket: too many open files 
WARN[0075] [UDP] dial 185.51.200.2:53: connect to 127.0.0.1:10801: dial tcp 127.0.0.1:10801: socket: too many open files 
WARN[0075] [UDP] dial 185.51.200.2:53: connect to 127.0.0.1:10801: dial tcp 127.0.0.1:10801: socket: too many open files 
WARN[0075] [UDP] dial 185.51.200.2:53: connect to 127.0.0.1:10801: dial tcp 127.0.0.1:10801: socket: too many open files 
WARN[0075] [UDP] dial 185.51.200.2:53: connect to 127.0.0.1:10801: dial tcp 127.0.0.1:10801: socket: too many open files 

### How to Reproduce

1. Add Specific Route
2. run tun2socks 
3. run xraycore

Using 127.0.0.1 socks, require policy based routing As of now only Linux works See my solution below tun2socks -> localhost cause loop hole, which stop 127.0.0.1 socks server to functioning. Depend on the socks server implementation, but usually socks port not open if a stream is not established See my solution for example Psiphon 127.0.0.1 socks Only work on Linux, support iptables user id range policy, or cgroup. tun2socks-127.0.0.1-loopback

github-actions[bot] commented 9 months ago

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 7 days