Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Memory leaks on Windows 11 using Tun2socks 2.5.2 (wintun 0.14.1) with Xray 1.8.17 #390

Open
2 tasks done
tw0ch opened this issue Aug 21, 2024 · 3 comments
Open
2 tasks done
Labels

Comments

@tw0ch
Copy link

tw0ch commented Aug 21, 2024

Verify steps

  • Is this something you can debug and fix? Send a pull request! Bug fixes and documentation fixes are welcome.
  • I have searched on the issue tracker for a related issue.

Version

2.5.2

What OS are you seeing the problem on?

Windows

Description

I am faced with the problem of large memory leaks when using the Xray-client with tun2socks (for local socks proxy) on Windows 11, here is my Xray config:

Xray-client config.json
{
  "dns": {
    "disableCache": true,
    "hosts": {
      "one.one.one.one": [
        "1.1.1.1"
      ]
    },
    "queryStrategy": "UseIPv4",
    "servers": [
      {
        "address": "https://one.one.one.one/dns-query"
      },
      {
        "address": "https+local://dns.quad9.net/dns-query",
        "domains": [
          "regexp:\\.ru$",
          "geosite:category-gov-ru",
          "geosite:yandex",
          "geosite:mailru"
        ]
      },
      "1.1.1.1"
    ]
  },
  "inbounds": [
    {
      "listen": "127.0.0.1",
      "port": 10808,
      "protocol": "socks",
      "settings": {
        "auth": "noauth",
        "udp": true,
        "userLevel": 8
      },
      "sniffing": {
        "destOverride": [
          "http",
          "tls"
        ],
        "enabled": true
      },
      "tag": "socks"
    },
    {
      "listen": "127.0.0.1",
      "port": 10809,
      "protocol": "http",
      "settings": {
        "userLevel": 8
      },
      "tag": "http"
    }
  ],
  "log": {
    "dnsLog": true,
    "loglevel": "debug"
  },
  "outbounds": [
    {
      "mux": {
        "concurrency": 8,
        "enabled": false
      },
      "protocol": "vless",
      "settings": {
        "vnext": [
          {
            "address": "my-server-address",
            "port": 443,
            "users": [
              {
                "encryption": "none",
                "flow": "xtls-rprx-vision",
                "id": "my-server-id",
                "level": 8,
                "security": "auto"
              }
            ]
          }
        ]
      },
      "streamSettings": {
        "network": "tcp",
        "realitySettings": {
          "allowInsecure": false,
          "fingerprint": "chrome",
          "publicKey": "my-server-key",
          "serverName": "my-server-name",
          "shortId": "my-server-short-id",
          "show": false,
          "spiderX": ""
        },
        "security": "reality",
        "tcpSettings": {
          "header": {
            "type": "none"
          }
        }
      },
      "tag": "proxy"
    },
    {
      "protocol": "freedom",
      "settings": {},
      "tag": "direct"
    },
    {
      "protocol": "blackhole",
      "settings": {
        "response": {
          "type": "http"
        }
      },
      "tag": "block"
    }
  ],
  "routing": {
    "domainStrategy": "IPIfNonMatch",
    "rules": [
      {
        "ip": [
          "1.1.1.1"
        ],
        "outboundTag": "proxy",
        "port": "53",
        "type": "field"
      },
      {
        "inboundTag": [
          "dnsQuery"
        ],
        "outboundTag": "proxy",
        "type": "field"
      },
      {
        "outboundTag": "dnsOut",
        "port": "53",
        "type": "field"
      },
      {
        "ip": [
          "1.1.1.1"
        ],
        "outboundTag": "proxy",
        "type": "field"
      },
      {
        "outboundTag": "block",
        "protocol": [
          "bittorrent"
        ],
        "type": "field"
      },
      {
        "ip": [
          "geoip:ru"
        ],
        "outboundTag": "direct",
        "type": "field"
      },
      {
        "ip": [
          "geoip:private"
        ],
        "outboundTag": "direct",
        "type": "field"
      },
      {
        "domain": [
          "regexp:\\.ru$"
        ],
        "outboundTag": "direct",
        "type": "field"
      },
      {
        "domain": [
          "geosite:category-gov-ru"
        ],
        "outboundTag": "direct",
        "type": "field"
      },
      {
        "domain": [
          "geosite:yandex"
        ],
        "outboundTag": "direct",
        "type": "field"
      },
      {
        "domain": [
          "geosite:mailru"
        ],
        "outboundTag": "direct",
        "type": "field"
      }
    ]
  }
}

Leaks reaches 2GB+ on Tun2socks.exe and 1GB+ on Xray.exe

tun2socks-memory-leak
xray-memory-leak

I guess my virtual adapter is being created incorrectly in some way and traffic just starts to overflow the Tun2socks and Xray stacks. Maybe someone can provide me with other tools for local socks-proxying to the xray-client (at 127.0.0.1:10808) I will be very grateful!

CLI or Config

.\tun2socks.exe -device tun-device -proxy 127.0.0.1:10808

Logs

[Tun2socks] time="2024-08-16T10:48:56+03:00" level=warning msg="[UDP] dial "server-ip": connect to 127.0.0.1:10808: dial tcp 127.0.0.1:10808: bind: An operation on a socket could not be performed because the system lacked sufficient buffer space or because a queue was full."
[Tun2socks] time="2024-08-16T10:48:58+03:00" level=warning msg="[UDP] dial "server-ip": connect to 127.0.0.1:10808: dial tcp 127.0.0.1:10808: connectex: Only one usage of each socket address (protocol/network address/port) is normally permitted."

How to Reproduce

  1. In cmd run Xray-core as admin with config from the description :
.\xray.exe
  1. In another cmd run Tun2socks as admin:
.\tun2socks.exe -device tun-device -proxy 127.0.0.1:10808
  1. In another cmd configure the virtual adapter:
netsh interface ip set address name=tun-device addr=10.0.236.10 source=static mask=255.255.255.0 gateway=none
  1. Set DNS from the xray-config for tun-device:
netsh interface ip set dns name=tun-device static (dns-ip-address, ex: 1.1.1.1)
  1. Adding routes to the local DNS table:
route add (xray-server-ip, ex: 172.210.11.100) mask 255.255.255.255 (windows-default-gateway-ip, ex: 192.168.0.1)
route add 0.0.0.0 mask 0.0.0.0 10.0.236.10
@xjasonlyu
Copy link
Owner

Just wondering, were you able to connect to internet after your setup using tun2socks and xray?

@tw0ch
Copy link
Author

tw0ch commented Aug 26, 2024

Yes, it was successful, what could be the problem?

Copy link

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

@github-actions github-actions bot added the Stale label Oct 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants