v2ray / v2ray-core

A platform for building proxies to bypass network restrictions.
https://www.v2ray.com/
MIT License
45.01k stars 8.95k forks source link

High cpu usage (100%) on server #763

Closed S-Tsunemori closed 6 years ago

S-Tsunemori commented 6 years ago

1) What version of V2Ray are you using (If you deploy different version on server and client, please explicitly point out)?

v2.5.1

2) What's your scenario of using V2Ray? E.g., Watching YouTube videos in Chrome via Socks/VMess proxy.

Proxy for browser & system (Internet Explorer) proxy setting.

3) What did you see? (Please describe in detail, such as timeout, fake TLS certificate etc)

The proxy works, but begins to eat up my CPU (100% usage) since a few days ago. I need to point out that I can still use the proxy (uses a different inbound, not sure about the mkcp inbound) even when it was on 100% though so v2ray isn't dead.

4) What's your expectation?

No more than 10% CPU usage as it used to be.

5) Please attach your configuration file (Mask IP addresses before submit this issue).

Server configuration: (inbound detour section)
    {
      "tag": "inbound_mkcp_main",
      "port": [*]000,
      "listen": "[IP]",
      "protocol": "vmess",
      "settings": {
        "clients": [
          {
            "id": "[UUID]",
            "level": 1,
            "alterId": 32
          }
        ],
        "detour": {
          "to": "inbound_mkcp_detour"
        }
      },
      "streamSettings": {
        "network": "kcp",
        "kcpSettings": {
          [KCPSETTINGS]
        }
      }
    },
    {
      "tag": "inbound_mkcp_detour",
      "port": "[*]001-[*]030",
      "listen": "[IP]",
      "protocol": "vmess",
      "settings": {
        "default": {
          "level": 1,
          "alterId": 32
        }
      },
      "allocate": {
        "strategy": "random",
        "concurrency": 2,
        "refresh": 3
      }
    }
Client configuration: (outbound detour section)
    {
      "protocol": "vmess",
      "settings": {
        "vnext": [
          {
            "address": "[IP]",
            "port": [*]000,
            "users": [
              {
                "id": "[UUID]",
                "alterId": 32,
                "security": "aes-128-gcm"
              }
            ]
          }
        ]
      },
      "streamSettings": {
        "network": "kcp",
        "kcpSettings": {
          [KCPSETTINGS]
        }
      },
      "tag": "outbound-mkcp"
    }

6) Please attach error logs, especially the bottom lines if the file is large. Error log file is usually at /var/log/v2ray/error.log on Linux.

Server error log:
2017/11/25 20:21:41 [Warning]App|Proxyman|Inbound: failed to create TCP worker > App|Proxyman|Inbound: failed to listen TCP on [*]017 > Transport|Internet: failed to listen on address: [IP]:[*]017 > listen udp [IP]:[*]017: bind: address already in use
2017/11/25 20:30:41 [Warning]App|Proxyman|Inbound: failed to create TCP worker > App|Proxyman|Inbound: failed to listen TCP on [*]011 > Transport|Internet: failed to listen on address: [IP]:[*]011 > listen udp [IP]:[*]011: bind: address already in use
2017/11/25 22:03:01 [Warning]App|Proxyman|Inbound: connection ends > Proxy|VMess|Inbound: unable to set read deadline > Transport|Internet|mKCP: Connection closed.
2017/11/25 22:09:41 [Warning]App|Proxyman|Inbound: failed to create TCP worker > App|Proxyman|Inbound: failed to listen TCP on [*]013 > Transport|Internet: failed to listen on address: [IP]:[*]013 > listen udp [IP]:[*]013: bind: address already in use
2017/11/25 22:21:41 [Warning]App|Proxyman|Inbound: failed to create TCP worker > App|Proxyman|Inbound: failed to listen TCP on [*]024 > Transport|Internet: failed to listen on address: [IP]:[*]024 > listen udp [IP]:[*]024: bind: address already in use
2017/11/25 23:12:41 [Warning]App|Proxyman|Inbound: failed to create TCP worker > App|Proxyman|Inbound: failed to listen TCP on [*]003 > Transport|Internet: failed to listen on address: [IP]:[*]003 > listen udp [IP]:[*]003: bind: address already in use
2017/11/26 00:15:41 [Warning]App|Proxyman|Inbound: failed to create TCP worker > App|Proxyman|Inbound: failed to listen TCP on [*]016 > Transport|Internet: failed to listen on address: [IP]:[*]016 > listen udp [IP]:[*]016: bind: address already in use
2017/11/26 00:45:41 [Warning]App|Proxyman|Inbound: failed to create TCP worker > App|Proxyman|Inbound: failed to listen TCP on [*]002 > Transport|Internet: failed to listen on address: [IP]:[*]002 > listen udp [IP]:[*]002: bind: address already in use
Client error log:
    //  wasn't enabled at the time.

7) Please attach access log. Access log is usually at '/var/log/v2ray/access.log' on Linux.

    // wasn't enabled at the time.
DarienRaymond commented 6 years ago

It seems that the ports for inbound_mkcp_detour are occupied by other processes.

Please use issue template to submit new issues.

S-Tsunemori commented 6 years ago

@DarienRaymond Sure, I'll use template next time, I've updated this one to fit the format as well.

On server I have only sshd listens on tcp 22, nginx listens on tcp 80 & 443, no other programs listening. The config I posted is the only inbound uses that range of ports, the main inbound listens on 127.0.0.1 using websocket which was reverse proxied by nginx - and during that 100% CPU usage period the main inbound works just fine.

I've also updated my server error log on top to include the time stamps, as you can see, even there's a lot (well I only posted a few lines but they're just the same thing over and over again) of those messages in the recent few days, it's not happening constantly (once every 10-40 mintues) and the last line of "failed to listen" message time stamp is on 2017/11/29 22:21:02 but my monitor page shows high CPU usage continues after that until I restarted v2ray service today - so I don't know if it could be the cause of high CPU usage but there's really nothing else in the error log (well, except for [Warning]Core: V2Ray started). I've searched in the full error log, and found almost every port from 001~030 has failed listening, except for 007. Port 000 didn't show up in the error log as well.

There're also those "failed to listen" messages (already in use) before I v2.51 was released (I can tell from the time stamp) but that was like only once or twice in a few days and didn't cause any extreme CPU usage or connection failure.

BTW, why does the error log say failed to listen TCP on ? I'm using mkcp, shouldn't that mean it only listens on udp ports? (I only allowed udp connections on those ports in ufw and the proxy worked fine)

I've already updated this server to v3.0 but I have another server with similar configuration (mkcp, same range of ports used) and haven't been updated. That server status is normal as the time I'm typing this, I'll keep the old version on that server to see if the same high CPU usage behavior happens on it as well.

DarienRaymond commented 6 years ago

You can disable 'inbound_mkcp_detour' see whether V2Ray still runs at 100% CPU or not. When an inbound uses dynamic ports and port allocation fails like this, it takes 100% CPU to find another available ports.