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 Report: Inbound Addition Failure in Xray API #3806

Open
4 tasks done
EchoVRC opened this issue Sep 13, 2024 · 7 comments
Open
4 tasks done

Bug Report: Inbound Addition Failure in Xray API #3806

EchoVRC opened this issue Sep 13, 2024 · 7 comments

Comments

@EchoVRC
Copy link

EchoVRC commented Sep 13, 2024

Integrity requirements

  • I confirm that I have read the documentation, understand the meaning of all the configuration items I wrote, and did not pile up seemingly useful options or default values.
  • I provided the complete config and logs, rather than just providing the truncated parts based on my own judgment.
  • I searched issues and did not find any similar issues.
  • The problem can be successfully reproduced in the latest Release

Description

Summary:
When removing and immediately re-adding an inbound with the same tag using the Xray API, the system throws errors. The initial attempt results in a DeadlineExceeded error, and subsequent attempts return an existing tag found error. This indicates a race condition or incomplete state clearance in the Xray API when handling rapid inbound changes.

img

Reproduction Method

./xray api rmi --server 127.0.0.1:9000 wireguard-7; ./xray api adi --server 127.0.0.1:9000 generated_config/wireguard.json

generated_config/wireguard.json

{
  "inbounds": [
    {
      "tag": "wireguard-7",
      "listen": "0.0.0.0",
      "port": 51820,
      "protocol": "wireguard",
      "settings": {
        "secretKey": "iBL/rcU9IrJHkohqPTVSHH2XytBO96nhpIPk7PxiOW0=",
        "peers": [
          {
            "publicKey": "dB53utuSg2/89INZGtFdAEtZ6rGDkPF5kXYFtepIkQg=",
            "allowedIPs": [
              "169.254.0.2/32"
            ]
          }
        ],
        "kernelMode": false
      }
    }
  ]
}

Client config


N/A

Server config


{
  "log": {
    "loglevel": "debug"
  },
  "stats": {},
  "api": {
    "listen": "127.0.0.1:9000",
    "services": [
      "HandlerService",
      "LoggerService",
      "StatsService",
      "RoutingService",
      "ReflectionService",
      "DNSService",
      "TransportService",
      "PolicyService",
      "ReverseService"
    ],
    "tag": "api"
  },
  "policy": {
    "levels": {
      "0": {
        "statsUserUplink": true,
        "statsUserDownlink": true
      }
    }
  },
  "inbounds": [
  ],
  "outbounds": [
    {
      "protocol": "freedom",
      "settings": {}
    },
    {
      "protocol": "blackhole",
      "tag": "blocked"
    }
  ],
  "routing": {
    "domainStrategy": "AsIs",
    "rules": [
      {
        "type": "field",
        "inboundTag": ["api"],
        "outboundTag": "api"
      },
      {
        "type": "field",
        "outboundTag": "blocked",
        "ip": ["geoip:private"]
      },
      {
        "type": "field",
        "outboundTag": "blocked",
        "protocol": ["bittorrent"]
      }
    ]
  }
}

Client log


N/A

Server log


root@v1655092:/opt/app# ./xray -c generated_config/xray_config.json
Xray 1.8.24 (Xray, Penetrates Everything.) 6baad79 (go1.23.0 linux/amd64)
A unified platform for anti-censorship.
2024/09/13 04:36:08 [Info] infra/conf/serial: Reading config: &{Name:generated_config/xray_config.json Format:json}
2024/09/13 04:36:08 [Debug] app/log: Logger started
2024/09/13 04:36:08 [Info] app/commander: API server listening on 127.0.0.1:9000
2024/09/13 04:36:08 [Warning] core: Xray 1.8.24 started
2024/09/13 04:36:17 [Debug] Routine: decryption worker 1 - started
2024/09/13 04:36:17 [Debug] UAPI: Updating private key
2024/09/13 04:36:17 [Debug] Routine: handshake worker 2 - started
2024/09/13 04:36:17 [Debug] Routine: handshake worker 1 - started
2024/09/13 04:36:17 [Debug] Routine: encryption worker 2 - started
2024/09/13 04:36:17 [Debug] Routine: encryption worker 1 - started
2024/09/13 04:36:17 [Debug] Routine: decryption worker 2 - started
2024/09/13 04:36:17 [Debug] Routine: encryption worker 3 - started
2024/09/13 04:36:17 [Debug] UAPI: Updating listen port
2024/09/13 04:36:17 [Debug] Routine: decryption worker 3 - started
2024/09/13 04:36:17 [Debug] Routine: handshake worker 3 - started
2024/09/13 04:36:17 [Debug] Routine: TUN reader - started
2024/09/13 04:36:17 [Debug] Routine: event worker - started
2024/09/13 04:36:17 [Debug] Interface up requested
2024/09/13 04:36:17 [Debug] peer(dB53…IkQg) - UAPI: Created
2024/09/13 04:36:17 [Debug] peer(dB53…IkQg) - UAPI: Adding allowedip
2024/09/13 04:36:17 [Debug] peer(dB53…IkQg) - Starting
2024/09/13 04:36:17 [Debug] UDP bind has been updated
2024/09/13 04:36:17 [Debug] Interface state was Down, requested Up, now Up
2024/09/13 04:36:17 [Debug] peer(dB53…IkQg) - Routine: sequential receiver - started
2024/09/13 04:36:17 [Debug] peer(dB53…IkQg) - Routine: sequential sender - started
2024/09/13 04:36:17 [Debug] Routine: receive incoming Open - started
2024/09/13 04:36:17 [Info] transport/internet/udp: listening UDP on 0.0.0.0:51820
2024/09/13 04:36:25 [Info] transport/internet/udp: failed to read UDP msg > read udp [::]:51820: use of closed network connection
2024/09/13 04:36:25 [Debug] UAPI: Updating private key
2024/09/13 04:36:25 [Debug] Routine: handshake worker 1 - started
2024/09/13 04:36:25 [Debug] Routine: encryption worker 1 - started
2024/09/13 04:36:25 [Debug] Routine: decryption worker 1 - started
2024/09/13 04:36:25 [Debug] Routine: encryption worker 3 - started
2024/09/13 04:36:25 [Debug] Routine: encryption worker 2 - started
2024/09/13 04:36:25 [Debug] Routine: decryption worker 2 - started
2024/09/13 04:36:25 [Debug] Routine: handshake worker 2 - started
2024/09/13 04:36:25 [Debug] Routine: decryption worker 3 - started
2024/09/13 04:36:25 [Debug] Routine: TUN reader - started
2024/09/13 04:36:25 [Debug] Routine: handshake worker 3 - started
2024/09/13 04:36:25 [Debug] UAPI: Updating listen port
2024/09/13 04:36:25 [Debug] Routine: event worker - started
2024/09/13 04:36:25 [Debug] Interface up requested
2024/09/13 04:36:25 [Debug] peer(dB53…IkQg) - UAPI: Created
2024/09/13 04:36:25 [Debug] peer(dB53…IkQg) - UAPI: Adding allowedip
2024/09/13 04:36:25 [Debug] peer(dB53…IkQg) - Starting
2024/09/13 04:36:25 [Debug] Routine: receive incoming Open - started
2024/09/13 04:36:25 [Info] transport/internet/udp: listening UDP on 0.0.0.0:51820
2024/09/13 04:36:27 [Info] transport/internet/udp: failed to read UDP msg > read udp [::]:51820: use of closed network connection
2024/09/13 04:36:27 [Debug] UAPI: Updating private key
2024/09/13 04:36:27 [Debug] Routine: encryption worker 2 - started
2024/09/13 04:36:27 [Debug] Routine: decryption worker 3 - started
2024/09/13 04:36:27 [Debug] Routine: decryption worker 2 - started
2024/09/13 04:36:27 [Debug] Routine: encryption worker 1 - started
2024/09/13 04:36:27 [Debug] Routine: decryption worker 1 - started
2024/09/13 04:36:27 [Debug] Routine: handshake worker 2 - started
2024/09/13 04:36:27 [Debug] Routine: encryption worker 3 - started
2024/09/13 04:36:27 [Debug] Routine: handshake worker 1 - started
2024/09/13 04:36:27 [Debug] Routine: TUN reader - started
2024/09/13 04:36:27 [Debug] Routine: handshake worker 3 - started
2024/09/13 04:36:27 [Debug] Routine: event worker - started
2024/09/13 04:36:27 [Debug] Interface up requested
2024/09/13 04:36:27 [Debug] UAPI: Updating listen port
2024/09/13 04:36:27 [Debug] UDP bind has been updated
2024/09/13 04:36:27 [Debug] Routine: receive incoming Open - started
2024/09/13 04:36:27 [Debug] Failed to receive Open packet: channel closed
2024/09/13 04:36:27 [Debug] Failed to receive Open packet: channel closed
2024/09/13 04:36:27 [Debug] Failed to receive Open packet: channel closed
2024/09/13 04:36:28 [Debug] Failed to receive Open packet: channel closed
2024/09/13 04:36:28 [Debug] Failed to receive Open packet: channel closed
2024/09/13 04:36:28 [Debug] Failed to receive Open packet: channel closed
2024/09/13 04:36:29 [Debug] Failed to receive Open packet: channel closed
2024/09/13 04:36:29 [Debug] Failed to receive Open packet: channel closed
2024/09/13 04:36:29 [Debug] Failed to receive Open packet: channel closed
2024/09/13 04:36:30 [Debug] Failed to receive Open packet: channel closed
2024/09/13 04:36:30 [Debug] Failed to receive Open packet: channel closed
2024/09/13 04:36:30 [Debug] Routine: receive incoming Open - stopped
2024/09/13 04:36:30 [Debug] UDP bind has been updated
2024/09/13 04:36:30 [Debug] Routine: receive incoming Open - started
2024/09/13 04:36:30 [Debug] peer(dB53…IkQg) - UAPI: Created
2024/09/13 04:36:30 [Debug] peer(dB53…IkQg) - UAPI: Adding allowedip
2024/09/13 04:36:30 [Debug] peer(dB53…IkQg) - Starting
2024/09/13 04:36:30 [Debug] Interface state was Down, requested Up, now Up
2024/09/13 04:36:30 [Debug] peer(dB53…IkQg) - Routine: sequential sender - started
2024/09/13 04:36:30 [Debug] peer(dB53…IkQg) - Routine: sequential receiver - started
2024/09/13 04:36:30 [Info] transport/internet/udp: listening UDP on 0.0.0.0:51820
2024/09/13 04:36:50 [Info] transport/internet/udp: failed to read UDP msg > read udp [::]:51820: use of closed network connection
2024/09/13 04:36:50 [Debug] UAPI: Updating private key
2024/09/13 04:36:50 [Debug] Routine: handshake worker 2 - started
2024/09/13 04:36:50 [Debug] Routine: encryption worker 1 - started
2024/09/13 04:36:50 [Debug] Routine: decryption worker 1 - started
2024/09/13 04:36:50 [Debug] Routine: handshake worker 1 - started
2024/09/13 04:36:50 [Debug] Routine: encryption worker 2 - started
2024/09/13 04:36:50 [Debug] Routine: decryption worker 2 - started
2024/09/13 04:36:50 [Debug] Routine: TUN reader - started
2024/09/13 04:36:50 [Debug] Routine: event worker - started
2024/09/13 04:36:50 [Debug] Interface up requested
2024/09/13 04:36:50 [Debug] Routine: handshake worker 3 - started
2024/09/13 04:36:50 [Debug] Routine: encryption worker 3 - started
2024/09/13 04:36:50 [Debug] Routine: decryption worker 3 - started
2024/09/13 04:36:50 [Debug] UAPI: Updating listen port
2024/09/13 04:36:50 [Debug] UDP bind has been updated
2024/09/13 04:36:50 [Debug] Routine: receive incoming Open - started
2024/09/13 04:36:50 [Debug] Failed to receive Open packet: channel closed
2024/09/13 04:36:51 [Debug] Failed to receive Open packet: channel closed
2024/09/13 04:36:51 [Debug] Failed to receive Open packet: channel closed
2024/09/13 04:36:51 [Debug] Failed to receive Open packet: channel closed
2024/09/13 04:36:52 [Debug] Failed to receive Open packet: channel closed
2024/09/13 04:36:52 [Debug] Failed to receive Open packet: channel closed
2024/09/13 04:36:52 [Debug] Failed to receive Open packet: channel closed
2024/09/13 04:36:53 [Debug] Failed to receive Open packet: channel closed
2024/09/13 04:36:53 [Debug] Failed to receive Open packet: channel closed
2024/09/13 04:36:53 [Debug] Failed to receive Open packet: channel closed
2024/09/13 04:36:54 [Debug] Failed to receive Open packet: channel closed
2024/09/13 04:36:54 [Debug] Routine: receive incoming Open - stopped
2024/09/13 04:36:54 [Debug] UDP bind has been updated
2024/09/13 04:36:54 [Debug] peer(dB53…IkQg) - UAPI: Created
2024/09/13 04:36:54 [Debug] peer(dB53…IkQg) - UAPI: Adding allowedip
2024/09/13 04:36:54 [Debug] peer(dB53…IkQg) - Starting
2024/09/13 04:36:54 [Debug] Interface state was Down, requested Up, now Up
2024/09/13 04:36:54 [Debug] Routine: receive incoming Open - started
2024/09/13 04:36:54 [Debug] peer(dB53…IkQg) - Routine: sequential sender - started
2024/09/13 04:36:54 [Debug] peer(dB53…IkQg) - Routine: sequential receiver - started
2024/09/13 04:36:54 [Info] transport/internet/udp: listening UDP on 0.0.0.0:51820

@yuhan6665
Copy link
Member

I think this is not a serious problem. (Not priority)
The inbound might takes a while to up, you can retry

@EchoVRC
Copy link
Author

EchoVRC commented Sep 16, 2024

The main problem is that if the json contains multiple inbound, it crashes on the first one and the others don't apply.

@yuhan6665
Copy link
Member

I think you should do one at a time. Can you post the crash log?

@EchoVRC
Copy link
Author

EchoVRC commented Sep 16, 2024

I've already done that. See Server log in the original post.

Another interesting point. If you remove wireguard inboond under load, the server keeps trying to send keepalive... Something seems to remain after removal(((
image

@Fangliding
Copy link
Member

Fangliding commented Sep 16, 2024

To some extent, the implementation of Wireguard inbound is not standardized.
I think we should declare which protocols the API is applicable to

@EchoVRC
Copy link
Author

EchoVRC commented Sep 16, 2024

Check out

func (tun *netTun) Close() error {
this part
I'm not an expert, but if you rewrite this part so that it closes all connections/goroutine normally, the problem will be solved

@moh3nasiyat
Copy link

hi in new ver xray i get this error when xray restart

"Failed to start: main: failed to load config files: [bin/config.json] > infra/conf: Failed to build SplitHTTP config. > infra/conf: maxConnections cannot be specified together with maxConcurrency"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants