Skip to content

v26.9.30: gRPC outbound never reconnects after connection loss (dial tcp ...: operation was canceled) #6876

Closed

Description

@LevL-max

Integrity requirements

  • I have read all the comments in the issue template and ensured that this issue meet the 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

Since v26.9.30, a gRPC outbound (without finalmask) cannot reconnect after its underlying connection is lost. The first connection works. After any disconnect (server restart, network blip, idle timeout), every redial fails immediately with dial tcp …: operation was canceled, and the outbound stays dead until the client process is restarted. v26.9.9 is not affected. The server side is fine: the server log shows no connection attempt at all after the restart.

Cause. #6754 (8267cf9) changed transport/internet/grpc/dial.go. In the branch without finalmask, the gRPC ContextDialer now calls

c, err = internet.DialSystem(ctx, dest, streamSettings.SocketSettings)

ctx and dest here are the arguments of getGrpcClient, i.e. the context of the first proxied connection that created the shared, cached grpc.ClientConn. When that connection finishes, its context is canceled, so every later redial of the channel fails instantly. The channel is only replaced in Shutdown state, so it never recovers. The finalmask branch right above it (and v26.9.9) correctly uses gctx.

Suggested fix (transport/internet/grpc/dial.go, L130 in v26.9.30):

 			} else {
-				c, err = internet.DialSystem(ctx, dest, streamSettings.SocketSettings)
+				c, err = internet.DialSystem(gctx, net.TCPDestination(address, port), streamSettings.SocketSettings)
 			}

This also restores the gRPC connect deadline and the TimeoutOnly flag that gctx carries.

Confirmation. Adding any UDP finalmask to the client, e.g. "finalmask": { "udp": [ { "type": "mkcp-legacy" } ] }, makes the dial go through FinalMask.DialTCP(gctx, …), and the problem disappears.

Note: with loglevel: warning the failure is invisible, because the error is logged at Info.

Reproduction Method

  1. Start server.json and client.json below (both v26.9.30, linux/amd64).
  2. curl -x socks5h://127.0.0.1:20808 https://www.google.com/generate_204 → 204.
  3. Restart the server process; the client keeps running.
  4. Repeat the curl → fails. Client log: Cannot dial gRPC > rpc error: code = Unavailable desc = connection error: desc = "transport: Error while dialing: dial tcp 127.0.0.1:20443: operation was canceled". It does not recover until the client is restarted.

Same configs and steps, different client builds:

Client Before server restart After restart (3 tries)
v26.9.9 204 204 204 204
v26.9.30 204 000 000 000
v26.9.30 + finalmask.udp: mkcp-legacy 204 204 204 204

Client config

Details

{
  "log": { "loglevel": "debug", "dnsLog": true },
  "inbounds": [ { "listen": "127.0.0.1", "port": 20808, "protocol": "socks", "settings": { "udp": true } } ],
  "outbounds": [
    {
      "protocol": "vless",
      "settings": { "vnext": [ { "address": "127.0.0.1", "port": 20443, "users": [ { "id": "66356bba-4b6c-4259-bd77-1d38dce21d17", "encryption": "none" } ] } ] },
      "streamSettings": { "network": "grpc", "grpcSettings": { "serviceName": "test" } }
    }
  ]
}

Server config

Details

{
  "log": { "loglevel": "debug", "dnsLog": true },
  "inbounds": [
    {
      "listen": "127.0.0.1",
      "port": 20443,
      "protocol": "vless",
      "settings": { "clients": [ { "id": "66356bba-4b6c-4259-bd77-1d38dce21d17" } ], "decryption": "none" },
      "streamSettings": { "network": "grpc", "grpcSettings": { "serviceName": "test" } }
    }
  ],
  "outbounds": [ { "protocol": "freedom" } ]
}

Client log

v26.9.30. The first request (13:24:31) works. The server was restarted at 13:24:32–33. All later requests fail.

Details

Xray 26.9.30 (Xray, Penetrates Everything.) b26a91d (go1.27.1 linux/amd64)
A unified platform for anti-censorship.
2026/09/30 13:24:29.668136 [Info] infra/conf/serial: Reading config: &{Name:/tmp/grpc-issue.0Xpyb9/client.json Format:json}
2026/09/30 13:24:29.669715 [Warning] common/errors: The feature gRPC transport (with unnecessary costs, etc.) is deprecated, not recommended for using and might be removed. Please migrate to XHTTP stream-up H2 as soon as possible.
2026/09/30 13:24:29.669875 [Debug] app/log: Logger started
2026/09/30 13:24:29.670260 [Debug] app/proxyman/inbound: creating stream worker on 127.0.0.1:20808
2026/09/30 13:24:29.670277 [Info] transport/internet/tcp: listening tcp on 127.0.0.1:20808
2026/09/30 13:24:29.670283 [Warning] core: Xray 26.9.30 started
2026/09/30 13:24:31.654919 from tcp:127.0.0.1:37062 accepted tcp:www.google.com:443
2026/09/30 13:24:31.654994 [Info] [593267635] proxy/socks: TCP Connect request to tcp:www.google.com:443
2026/09/30 13:24:31.655019 [Info] [593267635] app/dispatcher: default route for tcp:www.google.com:443
2026/09/30 13:24:31.655051 [Info] [593267635] transport/internet/grpc: creating connection to tcp:127.0.0.1:20443
2026/09/30 13:24:31.655124 [Debug] [593267635] transport/internet/grpc: using gRPC tun mode service name: `test` stream name: `Tun`
2026/09/30 13:24:31.655319 [Debug] [593267635] transport/internet: dialing to tcp:127.0.0.1:20443
2026/09/30 13:24:31.655738 [Info] [593267635] proxy/vless/outbound: tunneling request to tcp:www.google.com:443 via 127.0.0.1:20443
2026/09/30 13:24:35.454281 [Info] [2147938745] proxy/socks: TCP Connect request to tcp:www.google.com:443
2026/09/30 13:24:35.454312 [Info] [2147938745] app/dispatcher: default route for tcp:www.google.com:443
2026/09/30 13:24:35.454323 [Info] [2147938745] transport/internet/grpc: creating connection to tcp:127.0.0.1:20443
2026/09/30 13:24:35.454331 [Debug] [2147938745] transport/internet/grpc: using gRPC tun mode service name: `test` stream name: `Tun`
2026/09/30 13:24:35.454332 from tcp:127.0.0.1:37078 accepted tcp:www.google.com:443
2026/09/30 13:24:35.454536 [Debug] [593267635] transport/internet: dialing to tcp:127.0.0.1:20443
2026/09/30 13:24:35.454659 [Info] [2147938745] transport/internet/grpc: creating connection to tcp:127.0.0.1:20443
2026/09/30 13:24:35.454675 [Debug] [2147938745] transport/internet/grpc: using gRPC tun mode service name: `test` stream name: `Tun`
2026/09/30 13:24:35.655374 [Info] [2147938745] transport/internet/grpc: creating connection to tcp:127.0.0.1:20443
2026/09/30 13:24:35.655436 [Debug] [2147938745] transport/internet/grpc: using gRPC tun mode service name: `test` stream name: `Tun`
2026/09/30 13:24:35.955918 [Debug] [593267635] transport/internet: dialing to tcp:127.0.0.1:20443
2026/09/30 13:24:36.056060 [Info] [2147938745] transport/internet/grpc: creating connection to tcp:127.0.0.1:20443
2026/09/30 13:24:36.056113 [Debug] [2147938745] transport/internet/grpc: using gRPC tun mode service name: `test` stream name: `Tun`
2026/09/30 13:24:36.656928 [Info] [2147938745] transport/internet/grpc: creating connection to tcp:127.0.0.1:20443
2026/09/30 13:24:36.656998 [Debug] [2147938745] transport/internet/grpc: using gRPC tun mode service name: `test` stream name: `Tun`
2026/09/30 13:24:36.779797 [Debug] [593267635] transport/internet: dialing to tcp:127.0.0.1:20443
2026/09/30 13:24:37.457863 [Info] [2147938745] app/proxyman/outbound: app/proxyman/outbound: failed to process outbound traffic > proxy/vless/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 127.0.0.1:20443: operation was canceled"] > common/retry: all retry attempts failed
2026/09/30 13:24:37.727666 [Debug] [593267635] transport/internet: dialing to tcp:127.0.0.1:20443
2026/09/30 13:24:39.472240 [Info] [2161095927] proxy/socks: TCP Connect request to tcp:www.google.com:443
2026/09/30 13:24:39.472274 [Info] [2161095927] app/dispatcher: default route for tcp:www.google.com:443
2026/09/30 13:24:39.472308 [Info] [2161095927] transport/internet/grpc: creating connection to tcp:127.0.0.1:20443
2026/09/30 13:24:39.472315 [Debug] [2161095927] transport/internet/grpc: using gRPC tun mode service name: `test` stream name: `Tun`
2026/09/30 13:24:39.472323 [Info] [2161095927] transport/internet/grpc: creating connection to tcp:127.0.0.1:20443
2026/09/30 13:24:39.472329 [Debug] [2161095927] transport/internet/grpc: using gRPC tun mode service name: `test` stream name: `Tun`
2026/09/30 13:24:39.472314 from tcp:127.0.0.1:33086 accepted tcp:www.google.com:443
2026/09/30 13:24:39.595992 [Debug] [593267635] transport/internet: dialing to tcp:127.0.0.1:20443
2026/09/30 13:24:39.673406 [Info] [2161095927] transport/internet/grpc: creating connection to tcp:127.0.0.1:20443
2026/09/30 13:24:39.673475 [Debug] [2161095927] transport/internet/grpc: using gRPC tun mode service name: `test` stream name: `Tun`
2026/09/30 13:24:40.074598 [Info] [2161095927] transport/internet/grpc: creating connection to tcp:127.0.0.1:20443
2026/09/30 13:24:40.074630 [Debug] [2161095927] transport/internet/grpc: using gRPC tun mode service name: `test` stream name: `Tun`
2026/09/30 13:24:40.675450 [Info] [2161095927] transport/internet/grpc: creating connection to tcp:127.0.0.1:20443
2026/09/30 13:24:40.675523 [Debug] [2161095927] transport/internet/grpc: using gRPC tun mode service name: `test` stream name: `Tun`
2026/09/30 13:24:41.476122 [Info] [2161095927] app/proxyman/outbound: app/proxyman/outbound: failed to process outbound traffic > proxy/vless/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 127.0.0.1:20443: operation was canceled"] > common/retry: all retry attempts failed
2026/09/30 13:24:42.229408 [Debug] [593267635] transport/internet: dialing to tcp:127.0.0.1:20443
2026/09/30 13:24:43.490803 [Info] [407894382] proxy/socks: TCP Connect request to tcp:www.google.com:443
2026/09/30 13:24:43.490832 [Info] [407894382] app/dispatcher: default route for tcp:www.google.com:443
2026/09/30 13:24:43.490843 [Info] [407894382] transport/internet/grpc: creating connection to tcp:127.0.0.1:20443
2026/09/30 13:24:43.490853 [Debug] [407894382] transport/internet/grpc: using gRPC tun mode service name: `test` stream name: `Tun`
2026/09/30 13:24:43.490854 from tcp:127.0.0.1:33094 accepted tcp:www.google.com:443
2026/09/30 13:24:43.490937 [Info] [407894382] transport/internet/grpc: creating connection to tcp:127.0.0.1:20443
2026/09/30 13:24:43.490955 [Debug] [407894382] transport/internet/grpc: using gRPC tun mode service name: `test` stream name: `Tun`
2026/09/30 13:24:43.691251 [Info] [407894382] transport/internet/grpc: creating connection to tcp:127.0.0.1:20443
2026/09/30 13:24:43.691312 [Debug] [407894382] transport/internet/grpc: using gRPC tun mode service name: `test` stream name: `Tun`
2026/09/30 13:24:44.092336 [Info] [407894382] transport/internet/grpc: creating connection to tcp:127.0.0.1:20443
2026/09/30 13:24:44.092391 [Debug] [407894382] transport/internet/grpc: using gRPC tun mode service name: `test` stream name: `Tun`
2026/09/30 13:24:44.693347 [Info] [407894382] transport/internet/grpc: creating connection to tcp:127.0.0.1:20443
2026/09/30 13:24:44.693403 [Debug] [407894382] transport/internet/grpc: using gRPC tun mode service name: `test` stream name: `Tun`
2026/09/30 13:24:45.493968 [Info] [407894382] app/proxyman/outbound: app/proxyman/outbound: failed to process outbound traffic > proxy/vless/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 127.0.0.1:20443: operation was canceled"] > common/retry: all retry attempts failed

Server log

v26.9.30. After the restart there is no incoming connection at all: the client never reaches the server.

Details

Xray 26.9.30 (Xray, Penetrates Everything.) b26a91d (go1.27.1 linux/amd64)
A unified platform for anti-censorship.
2026/09/30 13:24:29.670020 [Info] infra/conf/serial: Reading config: &{Name:/tmp/grpc-issue.0Xpyb9/server.json Format:json}
2026/09/30 13:24:29.670688 [Warning] common/errors: The feature gRPC transport (with unnecessary costs, etc.) is deprecated, not recommended for using and might be removed. Please migrate to XHTTP stream-up H2 as soon as possible.
2026/09/30 13:24:29.672964 [Debug] app/log: Logger started
2026/09/30 13:24:29.673608 [Debug] app/proxyman/inbound: creating stream worker on 127.0.0.1:20443
2026/09/30 13:24:29.673627 [Warning] core: Xray 26.9.30 started
2026/09/30 13:24:29.673632 [Debug] transport/internet/grpc: gRPC listen for service name `test` tun `Tun` multi tun `TunMulti`
2026/09/30 13:24:31.700896 [Info] [1746134046] proxy/vless/inbound: firstLen = 554
2026/09/30 13:24:31.700982 [Info] [1746134046] proxy/vless/inbound: received request for tcp:www.google.com:443
2026/09/30 13:24:31.700998 [Info] [1746134046] app/dispatcher: default route for tcp:www.google.com:443
2026/09/30 13:24:31.701007 from 127.0.0.1:36182 accepted tcp:www.google.com:443
2026/09/30 13:24:31.702475 [Info] [1746134046] transport/internet/tcp: dialing TCP to tcp:www.google.com:443
2026/09/30 13:24:31.702517 [Debug] [1746134046] transport/internet: dialing to tcp:www.google.com:443
2026/09/30 13:24:31.712723 [Info] [1746134046] proxy/freedom: connection opened to tcp:www.google.com:443, local endpoint [redacted]:52190, remote endpoint 142.251.152.119:443
2026/09/30 13:24:31.712753 [Debug] [1746134046] proxy: CopyRawConn (maybe) readv
2026/09/30 13:24:31.741341 [Info] [1746134046] app/proxyman/outbound: app/proxyman/outbound: failed to process outbound traffic > proxy/freedom: connection ends > proxy/freedom: failed to process request > transport/internet/grpc/encoding: failed to fetch hunk from gRPC tunnel > rpc error: code = Canceled desc = context canceled
2026/09/30 13:24:32.741204 [Debug] app/log: Logger closing
--- server restarted ---
Xray 26.9.30 (Xray, Penetrates Everything.) b26a91d (go1.27.1 linux/amd64)
A unified platform for anti-censorship.
2026/09/30 13:24:33.464223 [Info] infra/conf/serial: Reading config: &{Name:/tmp/grpc-issue.0Xpyb9/server.json Format:json}
2026/09/30 13:24:33.464937 [Warning] common/errors: The feature gRPC transport (with unnecessary costs, etc.) is deprecated, not recommended for using and might be removed. Please migrate to XHTTP stream-up H2 as soon as possible.
2026/09/30 13:24:33.466183 [Debug] app/log: Logger started
2026/09/30 13:24:33.466360 [Debug] app/proxyman/inbound: creating stream worker on 127.0.0.1:20443
2026/09/30 13:24:33.466500 [Warning] core: Xray 26.9.30 started
2026/09/30 13:24:33.467097 [Debug] transport/internet/grpc: gRPC listen for service name `test` tun `Tun` multi tun `TunMulti`
2026/09/30 13:24:45.499361 [Debug] app/log: Logger closing
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions