hmgle / graftcp

A flexible tool for redirecting a given program's TCP traffic to SOCKS5 or HTTP proxy.
GNU General Public License v3.0
2.07k stars 174 forks source link

mgraftcp hangs(timeout) on Yearning #70

Closed tangr closed 5 days ago

tangr commented 2 months ago

Describe the bug A clear and concise description of what the bug is. I use mgraftcp on supervisord to run Yearning

mgraftcp --enable-debug-log --socks5=127.0.0.1:1080 ./Yearning run

I have ~10 datasources on yearing. It hangs on randomly when test connection.

and the output log: 2024/05/26 03:11:44 /Users/henryyee/PersonalProjects/Yearning-go/src/handler/manage/db/impl.go:30 [error] failed to initialize database, got error dial tcp: lookup rds endpoint on 10.253.128.2:53: read udp 127.0.0.1:38242->127.0.0.1:33147: read: connection refused

[2024-05-26 03:16:00] [INFO] Request PID: 72871, Source Addr: 127.0.0.1:55406, Dest Addr: 10.193.27.80:3306 [Info] 2024-05-26 03:16:01 "url":"/api/v2/fetch/base" "method":"GET" "status":200 "protocol":"HTTP/1.1" "remote_ip":"10.253.134.107" "bytes_in": "0 bytes" "bytes_out": "622 bytes" [2024-05-26 03:16:01] [INFO] Request PID: 72873, Source Addr: 127.0.0.1:55420, Dest Addr: 10.253.128.2:53

[2024-05-26 03:22:00] [INFO] Request PID: 72873, Source Addr: 127.0.0.1:44472, Dest Addr: 10.253.155.207:3306

It will be ok when the dest addr is 3306, but failed/hands/timeout when 53

To Reproduce Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Yearning(https://github.com/cookieY/Yearning) Version: 3.1.0 Uranus COMMON

Add more than 10 yearning mysql database sources, then test connection one by one, or test connection in same one database source again and again.

Expected behavior A clear and concise description of what you expected to happen.

Screenshots If applicable, add screenshots to help explain your problem. screenshot-20240526-112810

screenshot-20240526-112829

Desktop (please complete the following information):

Smartphone (please complete the following information):

Additional context Add any other context about the problem here.

hmgle commented 2 months ago

Based on the error message got error dial tcp: lookup rds endpoint on 10.253.128.2:53: read udp 127.0.0.1:38242->127.0.0.1:33147: read: connection refused, it appears that there was an error in obtaining the IP address for the "rds endpoint" from DNS. I'm unsure how graftcp might be affecting this step.

I've just updated the master branch's code to add more logs, specifically during the connect() phase, which may help in pinpointing the issue. You can pull the latest code and see if the error occurs before this print statement. @tangr

tangr commented 2 months ago

@hmgle Here is the new log, it really on dns port 53, but the mgraftcp currently only handles TCP connections. why the udp dns hangs.. And the 10.253.128.2:53 response was ok at the beginning, but failed after retries much more times.

[2024-05-27 00:32:56] [DEBUG] StorePidAddr(82488, 10.253.128.2:53) [Info] 2024-05-27 00:32:56 "url":"/api/v2/dash/top" "method":"GET" "status":200 "protocol":"HTTP/1.1" "remote_ip":"10.253.134.107" "bytes_in": "0 bytes" "bytes_out": "497 bytes" [2024-05-27 00:32:56] [DEBUG] StorePidAddr(82487, 10.253.155.207:3306) [2024-05-27 00:32:56] [INFO] Request PID: 82488, Source Addr: 127.0.0.1:59794, Dest Addr: 10.253.128.2:53 [Info] 2024-05-27 00:33:05 "url":"/api/v2/fetch/idc" "method":"GET" "status":200 "protocol":"HTTP/1.1" "remote_ip":"10.253.134.107" "bytes_in": "0 bytes" "bytes_out": "82 bytes" [2024-05-27 00:33:05] [DEBUG] StorePidAddr(82487, 10.253.128.2:53) [Info] 2024-05-27 00:33:05 "url":"/api/v2/manage/tpl" "method":"GET" "status":200 "protocol":"HTTP/1.1" "remote_ip":"10.253.134.107" "bytes_in": "0 bytes" "bytes_out": "833 bytes" [Info] 2024-05-27 00:33:05 "url":"/api/v2/manage/user" "method":"POST" "status":200 "protocol":"HTTP/1.1" "remote_ip":"10.253.134.107" "bytes_in": "0 bytes" "bytes_out": "5528 bytes" [2024-05-27 00:33:05] [DEBUG] StorePidAddr(82488, 10.253.155.207:3306) [2024-05-27 00:33:05] [INFO] Request PID: 82488, Source Addr: 127.0.0.1:53144, Dest Addr: 10.253.155.207:3306 [Info] 2024-05-27 00:33:05 "url":"/api/v2/manage/db" "method":"PUT" "status":200 "protocol":"HTTP/1.1" "remote_ip":"10.253.134.107" "bytes_in": "79 bytes" "bytes_out": "3110 bytes" [Info] 2024-05-27 00:33:09 "url":"/api/v2/manage/tpl" "method":"PUT" "status":200 "protocol":"HTTP/1.1" "remote_ip":"10.253.134.107" "bytes_in": "8 bytes" "bytes_out": "221 bytes" [2024-05-27 00:33:09] [DEBUG] StorePidAddr(82487, 10.193.27.80:3306) [2024-05-27 00:33:09] [INFO] Request PID: 82487, Source Addr: 127.0.0.1:53156, Dest Addr: 10.193.27.80:3306 [Info] 2024-05-27 00:33:09 "url":"/api/v2/fetch/base" "method":"GET" "status":200 "protocol":"HTTP/1.1" "remote_ip":"10.253.134.107" "bytes_in": "0 bytes" "bytes_out": "622 bytes" [2024-05-27 00:33:10] [DEBUG] StorePidAddr(82487, 10.193.27.80:3306) [2024-05-27 00:33:10] [INFO] Request PID: 82487, Source Addr: 127.0.0.1:37416, Dest Addr: 10.193.27.80:3306 [Info] 2024-05-27 00:33:11 "url":"/api/v2/manage/db" "method":"POST" "status":200 "protocol":"HTTP/1.1" "remote_ip":"10.253.134.107" "bytes_in": "485 bytes" "bytes_out": "69 bytes" [2024-05-27 00:33:12] [DEBUG] StorePidAddr(82486, 10.193.27.80:3306) [2024-05-27 00:33:12] [INFO] Request PID: 82486, Source Addr: 127.0.0.1:37420, Dest Addr: 10.193.27.80:3306 [Info] 2024-05-27 00:33:12 "url":"/api/v2/manage/db" "method":"POST" "status":200 "protocol":"HTTP/1.1" "remote_ip":"10.253.134.107" "bytes_in": "485 bytes" "bytes_out": "69 bytes" [2024-05-27 00:33:14] [DEBUG] StorePidAddr(82484, 10.193.27.80:3306) [2024-05-27 00:33:14] [INFO] Request PID: 82484, Source Addr: 127.0.0.1:37436, Dest Addr: 10.193.27.80:3306 [Info] 2024-05-27 00:33:14 "url":"/api/v2/manage/db" "method":"POST" "status":200 "protocol":"HTTP/1.1" "remote_ip":"10.253.134.107" "bytes_in": "485 bytes" "bytes_out": "69 bytes" [2024-05-27 00:33:15] [DEBUG] StorePidAddr(82486, 10.193.27.80:3306) [2024-05-27 00:33:15] [INFO] Request PID: 82486, Source Addr: 127.0.0.1:37448, Dest Addr: 10.193.27.80:3306 [Info] 2024-05-27 00:33:15 "url":"/api/v2/manage/db" "method":"POST" "status":200 "protocol":"HTTP/1.1" "remote_ip":"10.253.134.107" "bytes_in": "485 bytes" "bytes_out": "69 bytes" [2024-05-27 00:33:16] [DEBUG] StorePidAddr(82488, 10.193.27.80:3306) [2024-05-27 00:33:16] [INFO] Request PID: 82488, Source Addr: 127.0.0.1:37464, Dest Addr: 10.193.27.80:3306 [Info] 2024-05-27 00:33:16 "url":"/api/v2/manage/db" "method":"POST" "status":200 "protocol":"HTTP/1.1" "remote_ip":"10.253.134.107" "bytes_in": "485 bytes" "bytes_out": "69 bytes" [2024-05-27 00:33:17] [DEBUG] StorePidAddr(82484, 10.193.27.80:3306) [2024-05-27 00:33:17] [INFO] Request PID: 82484, Source Addr: 127.0.0.1:37472, Dest Addr: 10.193.27.80:3306 [Info] 2024-05-27 00:33:17 "url":"/api/v2/manage/db" "method":"POST" "status":200 "protocol":"HTTP/1.1" "remote_ip":"10.253.134.107" "bytes_in": "485 bytes" "bytes_out": "69 bytes" [2024-05-27 00:33:18] [DEBUG] StorePidAddr(82486, 10.193.27.80:3306) [2024-05-27 00:33:18] [INFO] Request PID: 82486, Source Addr: 127.0.0.1:37474, Dest Addr: 10.193.27.80:3306 [Info] 2024-05-27 00:33:18 "url":"/api/v2/manage/db" "method":"POST" "status":200 "protocol":"HTTP/1.1" "remote_ip":"10.253.134.107" "bytes_in": "485 bytes" "bytes_out": "69 bytes" [2024-05-27 00:33:19] [DEBUG] StorePidAddr(82486, 10.253.128.2:53) [2024-05-27 00:33:19] [DEBUG] StorePidAddr(82488, 10.193.27.80:3306) [2024-05-27 00:33:19] [INFO] Request PID: 82488, Source Addr: 127.0.0.1:37478, Dest Addr: 10.193.27.80:3306 [Info] 2024-05-27 00:33:19 "url":"/api/v2/manage/db" "method":"POST" "status":200 "protocol":"HTTP/1.1" "remote_ip":"10.253.134.107" "bytes_in": "485 bytes" "bytes_out": "69 bytes" [2024-05-27 00:33:19] [DEBUG] StorePidAddr(82484, 10.193.27.80:3306) [2024-05-27 00:33:19] [INFO] Request PID: 82486, Source Addr: 127.0.0.1:50970, Dest Addr: 10.253.128.2:53

hmgle commented 5 days ago

@tangr Fixing this issue based on the commit above. Feel free to reopen/comment or create a new one if the problem still exists. Thank you.