v2ray-core icon indicating copy to clipboard operation
v2ray-core copied to clipboard

服务端异常退出 "panic: concurrent write to websocket connection"

Open deadblue opened this issue 1 year ago • 2 comments

你正在使用哪个版本的 V2Ray?

服务端:v5.14.1 客户端:

  • PC: v5.14.1
  • 手机:v2rayNG v1.8.19 / 其他不明

你的使用场景是什么?

服务端是供几个朋友在一起用,在某一时刻出现 panic 后服务端挂掉,具体在做什么不清楚。

你看到的异常现象是什么?

服务端出现 panic 后非正常退出,监听的 Unix Domain Socket 没有被删除,导致 systemd 自动重启失败。

你期待看到的正常表现是怎样的?

不出现 panic,或出现 panic 后可正常删除 sock 文件再退出。

请附上你的配置

服务端配置:

{
  "log": {
    "access": {
      "type": "None"
    },
    "error": {
      "type": "Console",
      "level": "Info"
    }
  },

  "inbounds": [
    {
      "tag": "inbound-ws-trojan",
      "listen": "/tmp/v2ray-ws-trojan.sock",
      "protocol": "trojan",
      "settings": {
        "users": [
          "********-****-****-****-************"
        ]
      },
      "streamSettings": {
        "transport": "ws",
        "transportSettings": {
          "path": "/thi5_fi1e_n0t_3xis7s"
        },
        "security": "none"
      }
    }
  ],
  "outbounds": [{
    "tag": "outbound-direct",
    "protocol": "freedom"
  }, {
    "tag": "outbound-blackhole",
    "protocol": "blackhole"
  }],

  "router": {},
  "dns": {},
  "services": {
    "stats": {}
  }
}

客户端配置:

{
  "log": {
    "loglevel": "error"
  },
  "inbounds": [{
    "tag": "inbound-socks5",
    "port": 10808,
    "listen": "127.0.0.1",
    "protocol": "socks",
    "settings": {
      "udp": true
    },
    "sniffing": {
      "enabled": true,
      "destOverride": ["http", "tls"]
    }
  },
  {
    "tag": "inbound-http",
    "port": 10809,
    "listen": "0.0.0.0",
    "protocol": "http",
    "settings": {},
    "sniffing": {
      "enabled": true,
      "destOverride": ["http", "tls"]
    }
  }],

  "outbounds": [{
    "tag": "outbound-wss-trojan",
    "protocol": "trojan",
    "settings": {
      "servers": [{
        "address": "xxx.xxx.xxx",
        "port": xyxy,
        "password": "********-****-****-****-************"
      }]
    },
    "streamSettings": {
      "network": "ws",
      "security": "tls",
      "wsSettings": {
        "path": "/thi5_fi1e_n0t_3xis7s"
      },
      "tlsSettings": {
        "serverName": "xxx.xxx.xxx",
        "allowInsecure": false,
        "disableSystemRoot": true,
        "certificates": [{
          "usage": "verify",
          "certificate": [
            "-----BEGIN CERTIFICATE-----",
            "xxxxxxxxxxxxxxxxxxxxxxxxxxxx",
            "-----END CERTIFICATE-----"
          ]
        }]
      }
    }
  }, {
    "tag": "outbound-direct",
    "protocol": "freedom",
    "settings": {}
  }],

  "routing": {
    "domainStrategy": "AsIs",
    "domainMatcher": "mph",
    "rules": [{
      "type": "field",
      "ip": [
        "127.0.0.1",
        "10.0.0.0/8",
        "172.16.0.0/12",
        "192.168.0.0/16"
      ],
      "outboundTag": "outbound-direct"
    }]
  },

  "dns": {
    "servers": [
      "1.1.1.1",
      "8.8.8.8",
      "8.8.4.4",
      "localhost"
    ]
  },

  "policy": {}
}

请附上出错时软件输出的错误日志

服务器端错误日志:

见 journal 日志。

客户端错误日志:

N/A

请附上访问日志

N/A

其它相关的配置文件(如 Nginx)和相关日志

nginx 配置文件:

// upstream-v2ray.conf
upstream v2ray_ws_trojan {
    server unix:/tmp/v2ray-ws-trojan.sock;
}

// server-v2ray.conf
server {
    listen  xxxx-yyyy ssl http2;

    server_name xxx.xxx.xxx;

    server_tokens off;
    charset utf-8;

    ssl_certificate     /var/miku/etc/ssl/xxx-cert.pem;
    ssl_certificate_key /var/miku/etc/ssl/xxx-key.pem;

    location ^~ /thi5_fi1e_n0t_3xis7s {
        proxy_pass http://v2ray_ws_trojan;

        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "Upgrade";
    }

    location / {
        root  /var/miku/www/xxx;
        index index.html;
    }
}

如果 V2Ray 无法启动,请附上 --test 命令的输出

如果 V2Ray 服务运行异常,请附上 journal 日志:

v2ray[11989]: panic: concurrent write to websocket connection
v2ray[11989]: goroutine 4619702 [running]:
v2ray[11989]: github.com/gorilla/websocket.(*messageWriter).flushFrame(0xc00068bc90, 0x1, {0xc00097e02b?, 0x853a8d?, 0x0?})
v2ray[11989]:         github.com/gorilla/[email protected]/conn.go:632 +0x4b8
v2ray[11989]: github.com/gorilla/websocket.(*Conn).WriteMessage(0xc00056f340, 0xc00068bd10?, {0xc00097e000, 0x2b, 0x800})
v2ray[11989]:         github.com/gorilla/[email protected]/conn.go:785 +0x126
v2ray[11989]: github.com/v2fly/v2ray-core/v5/transport/internet/websocket.(*connection).Write(0x2?, {0xc00097e000?, 0x2b, 0x17aa2e8?})
v2ray[11989]:         github.com/v2fly/v2ray-core/v5/transport/internet/websocket/connection.go:125 +0x1b1
v2ray[11989]: github.com/v2fly/v2ray-core/v5/proxy/trojan.(*PacketWriter).writePacket(0xc0008f5920, {0xc000291000, 0x20, 0x40adba?}, {{0x17aa2e8?, 0xc00027fd7c?}, 0xd810?, 0xc0?})
v2ray[11989]:         github.com/v2fly/v2ray-core/v5/proxy/trojan/protocol.go:181 +0x49c
v2ray[11989]: github.com/v2fly/v2ray-core/v5/proxy/trojan.(*PacketWriter).WriteMultiBufferWithMetadata(0xc0008f5920, {0xc00068bec8, 0x1, 0xc00032e008?}, {{0x17aa2e8?, 0xc00027fd7c?}, 0x0?, 0x0?})
v2ray[11989]:         github.com/v2fly/v2ray-core/v5/proxy/trojan/protocol.go:131 +0xbf
v2ray[11989]: github.com/v2fly/v2ray-core/v5/proxy/trojan.(*Server).handleUDPPayload.func1({0x17aa208, 0xc0007fd720}, 0x1?)
v2ray[11989]:         github.com/v2fly/v2ray-core/v5/proxy/trojan/server.go:219 +0x5a
v2ray[11989]: github.com/v2fly/v2ray-core/v5/transport/internet/udp.handleInput({0x17aa208, 0xc0007fd720}, 0xc00068bfd0?, {{0x17aa2e8?, 0xc00027fd7c?}, 0x5924?, 0x0?}, 0xc000376be0)
v2ray[11989]:         github.com/v2fly/v2ray-core/v5/transport/internet/udp/dispatcher_split.go:119 +0x266
v2ray[11989]: created by github.com/v2fly/v2ray-core/v5/transport/internet/udp.(*Dispatcher).getInboundRay in goroutine 4619672
v2ray[11989]:         github.com/v2fly/v2ray-core/v5/transport/internet/udp/dispatcher_split.go:80 +0x4cb
systemd[1]: v2ray.service: Main process exited, code=exited, status=2/INVALIDARGUMENT

deadblue avatar Apr 16 '24 14:04 deadblue

This problem seems caused by upstream. gorilla/websocket#828

AkinoKaede avatar Apr 17 '24 04:04 AkinoKaede

This issue is stale because it has been open 120 days with no activity. Remove stale label or comment or this will be closed in 5 days

github-actions[bot] avatar Aug 16 '24 01:08 github-actions[bot]