cybozu-go / transocks

Transparent SOCKS5 / HTTP proxy in Go
MIT License
467 stars 61 forks source link

transocks dead lock when the socks met some issues #23

Open xixixihaha opened 4 years ago

xixixihaha commented 4 years ago

The socks proxy met some network issues, transaocks reported the issue but failed to reconnect to the proxy anymore even the proxy and network resumed working. looks like there is some issue about file handle as "GetOriginalDST failed" reported by transocks. Killing the transocks process and restart solved the issue.

Here is the log. 2020-05-28T13:36:06.938145Z J4205-me transocks error: "failed to connect to proxy server" client_addr="114.245.228.53:34304" dest_addr="96.45.191.222:21368" error="socks connect tcp 127.0.0.1:1080->96.45.191.222:21368: EOF" request_id="3a2dfc56-7762-2e55-d168-5c48fc8ffd3e" type="access" pid=11846 2020-05-28 21:36:06 ERROR: remote_recv_cb_recv: Connection reset by peer 2020-05-28T13:36:06.944690Z J4205-me transocks error: "failed to connect to proxy server" client_addr="114.245.228.53:49896" dest_addr="162.211.223.104:21368" error="socks connect tcp 127.0.0.1:1080->162.211.223.104:21368: EOF" request_id="3d2dfc56-7762-2e55-d168-5c48fc8ffd3e" type="access" pid=11846 2020-05-28 21:36:06 [simple-obfs] ERROR: remote_recv_cb_recv: Connection reset by peer 2020-05-28T13:36:09.247794Z J4205-me transocks error: "failed to connect to proxy server" client_addr="114.245.228.53:48854" dest_addr="13.35.102.189:443" error="socks connect tcp 127.0.0.1:1080->13.35.102.189:443: EOF" request_id="3c2dfc56-7762-2e55-d168-5c48fc8ffd3e" type="access" pid=11846 2020-05-28T13:36:10.054968Z J4205-me transocks error: "failed to connect to proxy server" client_addr="114.245.228.53:34410" dest_addr="96.45.191.222:21368" error="socks connect tcp 127.0.0.1:1080->96.45.191.222:21368: EOF" request_id="062dfc56-7762-2e55-d168-5c48fc8ffd3e" type="access" pid=11846 2020-05-28 21:36:10 ERROR: remote_recv_cb_recv: Connection reset by peer 2020-05-28T13:36:10.053874Z J4205-me transocks error: "failed to connect to proxy server" client_addr="114.245.228.53:49998" dest_addr="162.211.223.104:21368" error="socks connect tcp 127.0.0.1:1080->162.211.223.104:21368: EOF" request_id="092dfc56-7762-2e55-d168-5c48fc8ffd3e" type="access" pid=11846 2020-05-28 21:36:10 [simple-obfs] ERROR: remote_recv_cb_recv: Connection reset by peer 2020-05-28T13:36:12.948616Z J4205-me transocks error: "failed to connect to proxy server" client_addr="114.245.228.53:48956" dest_addr="13.35.102.189:443" error="socks connect tcp 127.0.0.1:1080->13.35.102.189:443: EOF" request_id="082dfc56-7762-2e55-d168-5c48fc8ffd3e" type="access" pid=11846 2020-05-28T13:36:12.981262Z J4205-me transocks error: "failed to connect to proxy server" client_addr="114.245.228.53:50088" dest_addr="162.211.223.104:21368" error="socks connect tcp 127.0.0.1:1080->162.211.223.104:21368: EOF" request_id="122dfc56-7762-2e55-d168-5c48fc8ffd3e" type="access" pid=11846 2020-05-28 21:36:12 [simple-obfs] ERROR: remote_recv_cb_recv: Connection reset by peer 2020-05-28T13:36:13.128439Z J4205-me transocks error: "failed to connect to proxy server" client_addr="114.245.228.53:35562" dest_addr="104.16.153.71:443" error="socks connect tcp 127.0.0.1:1080->104.16.153.71:443: EOF" request_id="152dfc56-7762-2e55-d168-5c48fc8ffd3e" type="access" pid=11846 2020-05-28T13:36:16.112691Z J4205-me transocks error: "GetOriginalDST failed" client_addr="114.245.228.53:57912" error="file tcp 127.0.0.1:1082->114.245.228.53:57912: fcntl: too many open files" request_id="7e2efc56-7762-2e55-d168-5c48fc8ffd3e" type="access" pid=11846 2020-05-28 21:36:16 ERROR: remote_recv_cb_recv: Connection reset by peer

ymmt2005 commented 3 years ago

error="file tcp 127.0.0.1:1082->114.245.228.53:57912: fcntl: too many open files"

This indicates there are too many open files. transocks might be leaking in some cases?

nishitaniyuki commented 3 years ago

Maybe something like the following is happening:

  1. No timeout is set to net.Dialer
  2. Something bad happens at the proxy server and a lot of proxy.Dialer.Dial get blocked
  3. Transocks reaches "Max open files" (in Linux the default value of "Max open files" soft limit is set to 1024)
  4. GetOriginalDST returns "fcntl: too many open files" error

We can probably set a timeout to net.Dialer to mitigate it.