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

客户端使用v4.39.2或v4.40.0,grpc断开连接后无法自行恢复连接,必须手动重启客户端。 #1059

Closed
IRN-Kawakaze opened this issue Jun 9, 2021 · 7 comments

Comments

@IRN-Kawakaze
Copy link

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

测试了以下组合:

服务端:v4.39.2,客户端:v4.39.2;

服务端:v4.38.3,客户端:v4.38.3;
服务端:v4.38.3,客户端:v4.39.2;
服务端:v4.38.3,客户端:v4.40.0;

服务端:v4.40.0,客户端:v4.38.3;
服务端:v4.40.0,客户端:v4.39.2;
服务端:v4.40.0,客户端:v4.40.0。

你的使用场景是什么?

服务端:nginx反代v2ray,开启tls,传输方式为grpc,传输协议为vmess(aead)。
客户端:使用chrome / firefox,利用v2rayN观看YouTube、GitHub和Google等网页。

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

1、使用一段时间之后(几十分钟到半天不等),所有被代理的网页均无法打开。并且日志出现大量报错(具体报错内容见后文),重启客户端或重新选择节点后可以恢复正常。

2、经测试,在前面列出的多个组合当中,所有 客户端为v4.39.2或v4.40.0 的组合,在使用过程中reboot服务器,可以100%复现该问题。
3、经测试,在前面列出的多个组合当中,所有 客户端为v4.38.3 的组合均无法复现该问题(即该问题不存在或被解决)。
(使用这几个版本组合进行测试的原因参考这一issue:#1056 ,怀疑是同一原因所致)

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

1、和其他传输方式或v4.38.3版本一致,能正常使用下去,不需要频繁手动重启客户端。
2、使用过程中reboot服务器之后,待服务器重启完毕,客户端可以自动恢复正常连接,不需要手动重启客户端。

请附上你的配置

服务端配置:

{
    "log": {
        "access": "/var/log/v2ray/access.log",
        "error": "/var/log/v2ray/error.log",
        "loglevel": "warning"
    },
    "inbounds": [
        {
            "sniffing": {
                "enabled": true,
                "destOverride": [
                    "http",
                    "tls"
                ]
            },
            "port": 10080,
            "listen": "127.0.0.1",
            "protocol": "vmess",
            "settings": {
                "clients": [
                    {
                        "id": "uuid1",
                        "level": 0,
                        "alterId": 0,
                        "email": "邮箱1"
                    },
                    {
                        "id": "uuid2",
                        "level": 0,
                        "alterId": 0,
                        "email": "邮箱2"
                    }
                ],
                "disableInsecureEncryption": true
            },
            "streamSettings": {
                "network": "ws",
                "security": "none",
                "wsSettings": {
                    "path": "/WSpath"
                }
            }
        },
        {
            "sniffing": {
                "enabled": true,
                "destOverride": [
                    "http",
                    "tls"
                ]
            },
            "port": 10081,
            "listen": "127.0.0.1",
            "protocol": "vmess",
            "settings": {
                "clients": [
                    {
                        "id": "uuid1",
                        "level": 0,
                        "alterId": 0,
                        "email": "邮箱1"
                    },
                    {
                        "id": "uuid2",
                        "level": 0,
                        "alterId": 0,
                        "email": "邮箱2"
                    }
                ],
                "disableInsecureEncryption": true
            },
            "streamSettings": {
                "network": "grpc",
                "security": "none",
                "grpcSettings": {
                    "serviceName": "GrpcServiceName"
                }
            }
        }
    ],
    "outbounds": [
        {
            "tag": "default",
            "protocol": "freedom",
            "settings": {}
        },
        {
            "tag": "block",
            "protocol": "blackhole",
            "settings": {}
        }
    ],
    "routing": {
        "domainStrategy": "IPIfNonMatch",
        "rules": [
            {
                "type": "field",
                "protocol": [
                    "bittorrent"
                ],
                "outboundTag": "block"
            },
            {
                "type": "field",
                "ip": [
                    "geoip:private"
                ],
                "user": [
                    "邮箱2"
                ],
                "outboundTag": "block"
            },
            {
                "type": "field",
                "domain": [
                    "geosite:private"
                ],
                "user": [
                    "邮箱2"
                ],
                "outboundTag": "block"
            }
        ]
    }
}

客户端配置:

{
  "policy": {
    "system": {
      "statsOutboundUplink": true,
      "statsOutboundDownlink": true
    }
  },
  "log": {
    "access": "",
    "error": "",
    "loglevel": "warning"
  },
  "inbounds": [
    {
      "tag": "socks",
      "port": 10080,
      "listen": "127.0.0.1",
      "protocol": "socks",
      "sniffing": {
        "enabled": true,
        "destOverride": [
          "http",
          "tls"
        ]
      },
      "settings": {
        "auth": "noauth",
        "udp": true,
        "allowTransparent": false
      }
    },
    {
      "tag": "http",
      "port": 10081,
      "listen": "127.0.0.1",
      "protocol": "http",
      "sniffing": {
        "enabled": true,
        "destOverride": [
          "http",
          "tls"
        ]
      },
      "settings": {
        "udp": false,
        "allowTransparent": false
      }
    },
    {
      "tag": "api",
      "port": 1170,
      "listen": "127.0.0.1",
      "protocol": "dokodemo-door",
      "settings": {
        "udp": false,
        "address": "127.0.0.1",
        "allowTransparent": false
      }
    }
  ],
  "outbounds": [
    {
      "tag": "proxy",
      "protocol": "vmess",
      "settings": {
        "vnext": [
          {
            "address": "domain.com",
            "port": 443,
            "users": [
              {
                "id": "uuid1",
                "alterId": 0,
                "email": "t@t.tt",
                "security": "auto"
              }
            ]
          }
        ]
      },
      "streamSettings": {
        "network": "grpc",
        "security": "tls",
        "tlsSettings": {
          "allowInsecure": false,
          "serverName": "domain.com"
        },
        "grpcSettings": {
          "serviceName": "GrpcServiceName",
          "multiMode": false
        }
      },
      "mux": {
        "enabled": false,
        "concurrency": -1
      }
    },
    {
      "tag": "direct",
      "protocol": "freedom",
      "settings": {}
    },
    {
      "tag": "block",
      "protocol": "blackhole",
      "settings": {
        "response": {
          "type": "http"
        }
      }
    }
  ],
  "stats": {},
  "api": {
    "tag": "api",
    "services": [
      "StatsService"
    ]
  },
  "dns": {
    "servers": [
      "1.0.0.1",
      "1.1.1.1"
    ]
  },
  "routing": {
    "domainStrategy": "IPIfNonMatch",
    "rules": [
      {
        "type": "field",
        "inboundTag": [
          "api"
        ],
        "outboundTag": "api"
      },
      {
        "type": "field",
        "outboundTag": "direct",
        "domain": [
          "domain:example-example.com",
          "domain:example-example2.com"
        ]
      },
      {
        "type": "field",
        "inboundTag": [],
        "outboundTag": "direct",
        "domain": [
          "geosite:private"
        ]
      },
      {
        "type": "field",
        "inboundTag": [],
        "outboundTag": "direct",
        "ip": [
          "geoip:private"
        ]
      },
      {
        "type": "field",
        "outboundTag": "direct",
        "domain": [
          "geosite:cn"
        ]
      },
      {
        "type": "field",
        "inboundTag": [],
        "outboundTag": "direct",
        "ip": [
          "geoip:cn"
        ]
      },
      {
        "type": "field",
        "port": "0-65535",
        "outboundTag": "proxy"
      }
    ]
  }
}

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

服务器端错误日志:

断开连接之后服务端nginx和v2ray均无相关日志产生。

客户端错误日志:

[Warning] [数字] app/proxyman/outbound: failed to process outbound traffic > proxy/vmess/outbound: failed to find an available destination > common/retry: [transport/internet/grpc: failed to dial Grpc > transport/internet/grpc: Cannot dial grpc > rpc error: code = Unavailable desc = connection error: desc = "transport: Error while dialing dial tcp: operation was canceled"] > common/retry: all retry attempts failed

请附上访问日志

断开连接之后服务端nginx和v2ray均无相关日志产生。

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

nginx的location部分的配置文件。

    location ~ ^/GrpcServiceName/Tun$
    {
        # Grpc协商失败时返回404
        if ($content_type !~ "application/grpc")
        {
            return 404;
        }
        client_max_body_size 0;
        client_body_buffer_size 8192k;
        client_body_timeout 31536000s;
        grpc_read_timeout 31536000s;
        grpc_send_timeout 31536000s;
        grpc_pass grpc://127.0.0.1:10081;
        # 在v2ray的access.log里显示真实的访问IP
        grpc_set_header X-Real-IP $remote_addr;
        grpc_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }

    location ~ ^/WSpath$
    {
        # WebSocket协商失败时返回404
        if ($http_upgrade != "websocket")
        {
            return 404;
        }
        proxy_redirect off;
        proxy_pass http://127.0.0.1:10080;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_set_header Host $host;
        # 在v2ray的access.log里显示真实的访问IP
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }

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

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

@ghost
Copy link

ghost commented Jun 19, 2021

Temporarily fix it by reverting related commits. You may use this forked repo.

@33lyl
Copy link

33lyl commented Jun 22, 2021

我也有遇到相同的问题,

@xiaokangwang
Copy link
Contributor

I am aware this issue, I will create a fix to redress this issue.

@IRN-Kawakaze
Copy link
Author

I am aware this issue, I will create a fix to redress this issue.

测试了一下,861d6be 确实解决了这个问题,感谢!

@xiaokangwang
Copy link
Contributor

I am aware this issue, I will create a fix to redress this issue.

测试了一下,861d6be 确实解决了这个问题,感谢!

那个修复又引入了别的问题,我等下发一个更新请再测试一下 v4.41.0 的情况。非常感谢。

@IRN-Kawakaze
Copy link
Author

I am aware this issue, I will create a fix to redress this issue.

测试了一下,861d6be 确实解决了这个问题,感谢!

那个修复又引入了别的问题,我等下发一个更新请再测试一下 v4.41.0 的情况。非常感谢。

测试了客户端v4.41.0 & 服务端v4.41.0客户端v4.41.0 & 服务端v4.38.3,都正常,grpc可以自动恢复连接。

@xiaokangwang
Copy link
Contributor

OK, 非常感谢

kyze8439690 pushed a commit to kyze8439690/v2ray-core-lib that referenced this issue Jul 7, 2021
It is important to use a detached context when creating shared transport connections that will outlive the initializing connection.

Otherwise, once the original initializing connection is cancelled, the transport connection will be cancelled as well.

This issue will be addressed in v5 by providing a transport session storage that also reduce the usage of globalDialerMap and other global variables.
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

3 participants