v2fly / v2ray-core

A platform for building proxies to bypass network restrictions.
https://v2fly.org
MIT License
29.53k stars 4.66k forks source link

加入domainMatcher mph後不能启动 #785

Closed kingwilliam closed 3 years ago

kingwilliam commented 3 years ago

What version of V2Ray are you using?

4.36.1

What's your scenario of using V2Ray?

加入 "domainMatcher": "mph",後不能启动 但 remark或删除 後就可正常启动

What problems have you encountered?

panic: runtime error: index out of range [0] with length 0 v2ray.service: Main process exited, code=exited, status=2/INVALIDARGUMENT

What's your expectation?

正常启动

Please attach your configuration here

Server configuration:

// Please attach your server configuration here.

Client configuration:

    "routing": {
       "domainMatcher": "mph",
        "rules": [
            // --- blocked ---
            {
                // exception
                "type": "field",
                "domain": [
                    "googleadservices.com",
                    "ad.doubleclick.net",
                    "gemini.yahoo.com"
                ],
                "outboundTag": "out-direct"
            },
            {
                "type": "field",
                "domain": [
                    "geosite:category-ads"
                ],
                "outboundTag": "blockout"
            },

            // -- ntp redirect ---
            {
                "type": "field",
                "port": 123,
                "network": "udp",
                "outboundTag": "out-ntp"
            }
        ]
    },

Please attach error logs here

Server error log:

// Please attach your server error log here.

Client error log:

// Please attach your client error log here.

Mar 16 15:46:52 os-ubuntu systemd[1]: Started V2Ray Service. Mar 16 15:46:52 os-ubuntu v2ray[5496]: V2Ray 4.36.1 (V2Fly, a community-driven edition of V2Ray.) Custom (go1.16 linux/amd64) Mar 16 15:46:52 os-ubuntu v2ray[5496]: A unified platform for anti-censorship. Mar 16 15:46:52 os-ubuntu v2ray[5496]: 2021/03/16 15:46:52 [Info] github.com/v2fly/v2ray-core/v4/main/jsonem: Reading config: /usr/local/etc/v2ray/config.json Mar 16 15:46:52 os-ubuntu v2ray[5496]: panic: runtime error: index out of range [0] with length 0 Mar 16 15:46:52 os-ubuntu v2ray[5496]: goroutine 22 [running]: Mar 16 15:46:52 os-ubuntu v2ray[5496]: github.com/v2fly/v2ray-core/v4/common/strmatcher.(MphMatcherGroup).Lookup(0xc000a35c20, 0xa64e067d, 0xc000038082, 0x4, 0xc000085bb8) Mar 16 15:46:52 os-ubuntu v2ray[5496]: #011github.com/v2fly/v2ray-core/v4/common/strmatcher/mph_matcher.go:162 +0xd5 Mar 16 15:46:52 os-ubuntu v2ray[5496]: github.com/v2fly/v2ray-core/v4/common/strmatcher.(MphMatcherGroup).Match(0xc000a35c20, 0xc000038060, 0x26, 0x26, 0xf3c068, 0xc00003c130) Mar 16 15:46:52 os-ubuntu v2ray[5496]: #011github.com/v2fly/v2ray-core/v4/common/strmatcher/mph_matcher.go:172 +0x9e Mar 16 15:46:52 os-ubuntu v2ray[5496]: github.com/v2fly/v2ray-core/v4/app/router.(DomainMatcher).ApplyDomain(0xc000a42300, 0xc000038060, 0x26, 0xe4d0c8) Mar 16 15:46:52 os-ubuntu v2ray[5496]: #011github.com/v2fly/v2ray-core/v4/app/router/condition.go:105 +0x5f Mar 16 15:46:52 os-ubuntu v2ray[5496]: github.com/v2fly/v2ray-core/v4/app/router.(DomainMatcher).Apply(0xc000a42300, 0xf43e08, 0xc0003c0228, 0xc00029c300) Mar 16 15:46:52 os-ubuntu v2ray[5496]: #011github.com/v2fly/v2ray-core/v4/app/router/condition.go:114 +0x56 Mar 16 15:46:52 os-ubuntu v2ray[5496]: github.com/v2fly/v2ray-core/v4/app/router.(ConditionChan).Apply(0xc00000d2f0, 0xf43e08, 0xc0003c0228, 0xe4d0c8) Mar 16 15:46:52 os-ubuntu v2ray[5496]: #011github.com/v2fly/v2ray-core/v4/app/router/condition.go:35 +0x79 Mar 16 15:46:52 os-ubuntu v2ray[5496]: github.com/v2fly/v2ray-core/v4/app/router.(Rule).Apply(...) Mar 16 15:46:52 os-ubuntu v2ray[5496]: #011github.com/v2fly/v2ray-core/v4/app/router/config.go:65 Mar 16 15:46:52 os-ubuntu v2ray[5496]: github.com/v2fly/v2ray-core/v4/app/router.(Router).pickRouteInternal(0xc000a2cd40, 0xf43e08, 0xc0003c0228, 0x70871d, 0xd61940, 0xc0003c0228, 0xe4d0c8, 0xcf6800) Mar 16 15:46:52 os-ubuntu v2ray[5496]: #011github.com/v2fly/v2ray-core/v4/app/router/router.go:95 +0xfe Mar 16 15:46:52 os-ubuntu v2ray[5496]: github.com/v2fly/v2ray-core/v4/app/router.(Router).PickRoute(0xc000a2cd40, 0xf43e08, 0xc0003c0228, 0xc0003c0228, 0x6258d6, 0x0, 0xc000080360) Mar 16 15:46:52 os-ubuntu v2ray[5496]: #011github.com/v2fly/v2ray-core/v4/app/router/router.go:73 +0x46 Mar 16 15:46:52 os-ubuntu v2ray[5496]: github.com/v2fly/v2ray-core/v4/app/dispatcher.(DefaultDispatcher).routedDispatch(0xc000a2cbc0, 0xf3af20, 0xc00029c600, 0xc0000c41a0, 0xf3c068, 0xc00003c130, 0x20$ Mar 16 15:46:52 os-ubuntu v2ray[5496]: #011github.com/v2fly/v2ray-core/v4/app/dispatcher/default.go:309 +0x3f3 Mar 16 15:46:52 os-ubuntu v2ray[5496]: github.com/v2fly/v2ray-core/v4/app/dispatcher.(DefaultDispatcher).Dispatch.func1(0xc0000c41a0, 0xf3af20, 0xc00029c600, 0xc000a303c0, 0x2, 0x2, 0xc000080001, 0xc0$ Mar 16 15:46:52 os-ubuntu v2ray[5496]: #011github.com/v2fly/v2ray-core/v4/app/dispatcher/default.go:242 +0x159 Mar 16 15:46:52 os-ubuntu v2ray[5496]: created by github.com/v2fly/v2ray-core/v4/app/dispatcher.(*DefaultDispatcher).Dispatch Mar 16 15:46:52 os-ubuntu v2ray[5496]: #011github.com/v2fly/v2ray-core/v4/app/dispatcher/default.go:227 +0x675 Mar 16 15:46:52 os-ubuntu systemd[1]: v2ray.service: Main process exited, code=exited, status=2/INVALIDARGUMENT Mar 16 15:46:52 os-ubuntu systemd[1]: v2ray.service: Failed with result 'exit-code'. Mar 16 15:46:52 os-ubuntu systemd[1]: v2ray.service: Service hold-off time over, scheduling restart. Mar 16 15:46:52 os-ubuntu systemd[1]: v2ray.service: Scheduled restart job, restart counter is at 5. Mar 16 15:46:52 os-ubuntu systemd[1]: Stopped V2Ray Service. Mar 16 15:46:52 os-ubuntu systemd[1]: v2ray.service: Start request repeated too quickly. Mar 16 15:46:52 os-ubuntu systemd[1]: v2ray.service: Failed with result 'exit-code'. Mar 16 15:46:52 os-ubuntu systemd[1]: Failed to start V2Ray Service.

// Please attach your server access log here.

Other configurations (such as Nginx) and logs here

If V2Ray cannot start up, please attach output from --test command

If V2Ray service is abnormal, please attach journal log here

chromer030 commented 3 years ago

same crash : without applying rules, it's ok and no crash. Client Config :

  "routing": {
    "domainStrategy": "AsIs",
    "domainMatcher": "mph",
    "rules": [
      {
        "inboundTag": [
          "dns-in"
        ],
        "outboundTag": "dns-out",
        "type": "field"
      },
      {
        "ip": [
          "1.1.1.1"
        ],
        "outboundTag": "proxy",
        "port": "53",
        "type": "field"
      },
      {
        "ip": [
          "1.1.1.1"
        ],
        "outboundTag": "direct",
        "port": "53",
        "type": "field"
      },
      {
        "ip": [
          "1.1.1.1"
        ],
        "outboundTag": "direct",
        "port": "53",
        "type": "field"
      },
      {
        "domain": [
          "192.168.0.0/8
        ],
        "outboundTag": "direct",
        "type": "field"
      }
    ]
  },
2021/03/16 13:10:07 [Debug] github.com/v2fly/v2ray-core/v4/app/log: Logger started
2021/03/16 13:10:07 [Info] github.com/v2fly/v2ray-core/v4/app/dns: DNS: created UDP client initialized for 1.1.1.1:53
2021/03/16 13:10:07 [Debug] github.com/v2fly/v2ray-core/v4/app/router: MphDomainMatcher is enabled for 1domain rules(s)
2021/03/16 13:10:07 [Debug] github.com/v2fly/v2ray-core/v4/app/stats: create new counter inbound>>>socks>>>traffic>>>uplink
2021/03/16 13:10:07 [Debug] github.com/v2fly/v2ray-core/v4/app/stats: create new counter inbound>>>socks>>>traffic>>>downlink
2021/03/16 13:10:07 [Debug] github.com/v2fly/v2ray-core/v4/app/proxyman/inbound: creating stream worker on 127.0.0.1:10808
2021/03/16 13:10:07 [Debug] github.com/v2fly/v2ray-core/v4/app/stats: create new counter inbound>>>http>>>traffic>>>uplink
2021/03/16 13:10:07 [Debug] github.com/v2fly/v2ray-core/v4/app/stats: create new counter inbound>>>http>>>traffic>>>downlink
2021/03/16 13:10:07 [Debug] github.com/v2fly/v2ray-core/v4/app/proxyman/inbound: creating stream worker on 127.0.0.1:10809
2021/03/16 13:10:07 [Debug] github.com/v2fly/v2ray-core/v4/app/stats: create new counter inbound>>>dns-in>>>traffic>>>uplink
2021/03/16 13:10:07 [Debug] github.com/v2fly/v2ray-core/v4/app/stats: create new counter inbound>>>dns-in>>>traffic>>>downlink
2021/03/16 13:10:07 [Debug] github.com/v2fly/v2ray-core/v4/app/proxyman/inbound: creating stream worker on 127.0.0.1:10853
2021/03/16 13:10:07 [Debug] github.com/v2fly/v2ray-core/v4/app/stats: create new counter outbound>>>Remote>>>traffic>>>uplink
2021/03/16 13:10:07 [Debug] github.com/v2fly/v2ray-core/v4/app/stats: create new counter outbound>>>Remote>>>traffic>>>downlink
2021/03/16 13:10:07 [Debug] github.com/v2fly/v2ray-core/v4/app/stats: create new counter outbound>>>direct>>>traffic>>>uplink
2021/03/16 13:10:07 [Debug] github.com/v2fly/v2ray-core/v4/app/stats: create new counter outbound>>>direct>>>traffic>>>downlink
2021/03/16 13:10:07 [Debug] github.com/v2fly/v2ray-core/v4/app/stats: create new counter outbound>>>block>>>traffic>>>uplink
2021/03/16 13:10:07 [Debug] github.com/v2fly/v2ray-core/v4/app/stats: create new counter outbound>>>block>>>traffic>>>downlink
2021/03/16 13:10:07 [Debug] github.com/v2fly/v2ray-core/v4/app/stats: create new counter outbound>>>dns-out>>>traffic>>>uplink
2021/03/16 13:10:07 [Debug] github.com/v2fly/v2ray-core/v4/app/stats: create new counter outbound>>>dns-out>>>traffic>>>downlink
2021/03/16 13:10:07 [Info] github.com/v2fly/v2ray-core/v4/transport/internet/tcp: listening TCP on 127.0.0.1:10808
2021/03/16 13:10:07 [Info] github.com/v2fly/v2ray-core/v4/transport/internet/udp: listening UDP on 127.0.0.1:10808
2021/03/16 13:10:07 [Info] github.com/v2fly/v2ray-core/v4/transport/internet/tcp: listening TCP on 127.0.0.1:10809
2021/03/16 13:10:07 [Info] github.com/v2fly/v2ray-core/v4/transport/internet/tcp: listening TCP on 127.0.0.1:10853
2021/03/16 13:10:07 [Info] github.com/v2fly/v2ray-core/v4/transport/internet/udp: listening UDP on 127.0.0.1:10853
2021/03/16 13:10:07 [Warning] github.com/v2fly/v2ray-core/v4: V2Ray 4.36.1 started
2021/03/16 13:10:07 [Info] [3388888526] github.com/v2fly/v2ray-core/v4/proxy/socks: TCP Connect request to tcp:alive.github.com:443
panic: runtime error: index out of range [0] with length 0

goroutine 7 [running]:
github.com/v2fly/v2ray-core/v4/common/strmatcher.(*MphMatcherGroup).Lookup(0xc000339b00, 0xa64e067d, 0xc00031a13c, 0x4, 0x40d9fb)
    github.com/v2fly/v2ray-core/v4/common/strmatcher/mph_matcher.go:162 +0xd5
github.com/v2fly/v2ray-core/v4/common/strmatcher.(*MphMatcherGroup).Match(0xc000339b00, 0xc00031a130, 0x10, 0x10, 0xf3c068, 0xc000332150)
    github.com/v2fly/v2ray-core/v4/common/strmatcher/mph_matcher.go:172 +0x9e
github.com/v2fly/v2ray-core/v4/app/router.(*DomainMatcher).ApplyDomain(0xc000333190, 0xc00031a130, 0x10, 0xc0002a0f00)
    github.com/v2fly/v2ray-core/v4/app/router/condition.go:105 +0x5f
github.com/v2fly/v2ray-core/v4/app/router.(*DomainMatcher).Apply(0xc000333190, 0xf43e08, 0xc00000c270, 0xc000346400)
    github.com/v2fly/v2ray-core/v4/app/router/condition.go:114 +0x56
github.com/v2fly/v2ray-core/v4/app/router.(*ConditionChan).Apply(0xc00030b920, 0xf43e08, 0xc00000c270, 0xe4d000)
    github.com/v2fly/v2ray-core/v4/app/router/condition.go:35 +0x79
github.com/v2fly/v2ray-core/v4/app/router.(*Rule).Apply(...)
    github.com/v2fly/v2ray-core/v4/app/router/config.go:65
github.com/v2fly/v2ray-core/v4/app/router.(*Router).pickRouteInternal(0xc0002f1f40, 0xf43e08, 0xc00000c270, 0x7086ae, 0xd61940, 0xc00000c270, 0xe4d0c8, 0xcf6800)
    github.com/v2fly/v2ray-core/v4/app/router/router.go:95 +0xfe
github.com/v2fly/v2ray-core/v4/app/router.(*Router).PickRoute(0xc0002f1f40, 0xf43e08, 0xc00000c270, 0xc00000c270, 0x6258d6, 0x0, 0xc0000829c0)
    github.com/v2fly/v2ray-core/v4/app/router/router.go:73 +0x46
github.com/v2fly/v2ray-core/v4/app/dispatcher.(*DefaultDispatcher).routedDispatch(0xc0002f1d40, 0xf3af20, 0xc0003466f0, 0xc0000740e0, 0xf3c068, 0xc000332150, 0x2000001bb)
    github.com/v2fly/v2ray-core/v4/app/dispatcher/default.go:309 +0x3f3
github.com/v2fly/v2ray-core/v4/app/dispatcher.(*DefaultDispatcher).Dispatch.func1(0xc0000740e0, 0xf3af20, 0xc0003466f0, 0xc0003346c0, 0x2, 0x2, 0xc000080001, 0xc000348080, 0xc00000c180, 0xc0003466c0, ...)
    github.com/v2fly/v2ray-core/v4/app/dispatcher/default.go:242 +0x159
created by github.com/v2fly/v2ray-core/v4/app/dispatcher.(*DefaultDispatcher).Dispatch
    github.com/v2fly/v2ray-core/v4/app/dispatcher/default.go:227 +0x675
darsvador commented 3 years ago

The reason is that mph does not deal with the absence of domain and full rules. #786 will fix this.