grpc network_error ai_generated true

UNAVAILABLE: grpc: connection error: connection reset by peer

ID: grpc/grpc-connection-reset-by-peer

Also available as: JSON · Markdown · 中文
76%Fix Rate
82%Confidence
1Evidence
2023-09-12First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
gRPC v1.42.0 active
gRPC v1.55.0 active
gRPC v1.61.0 active

Root Cause

The TCP connection was reset by the remote peer due to a crash, timeout, or firewall interference.

generic

中文

TCP 连接被远程对端重置,原因可能是崩溃、超时或防火墙干扰。

Official Documentation

https://grpc.io/docs/guides/error-handling/

Workarounds

  1. 75% success Configure the server to handle graceful shutdown and increase idle timeout. Example in Go: server := grpc.NewServer(grpc.KeepaliveParams(keepalive.ServerParameters{MaxConnectionIdle: 5 * time.Minute}))
    Configure the server to handle graceful shutdown and increase idle timeout. Example in Go: server := grpc.NewServer(grpc.KeepaliveParams(keepalive.ServerParameters{MaxConnectionIdle: 5 * time.Minute}))
  2. 80% success Use a connection pool with retry logic. In Python, use grpc.aio with automatic reconnection: channel = grpc.aio.insecure_channel('localhost:50051'); await channel.channel_ready()
    Use a connection pool with retry logic. In Python, use grpc.aio with automatic reconnection: channel = grpc.aio.insecure_channel('localhost:50051'); await channel.channel_ready()
  3. 70% success Check firewall or load balancer settings for idle connection timeouts. Increase TCP keepalive settings on both client and server (e.g., net.ipv4.tcp_keepalive_time=600).
    Check firewall or load balancer settings for idle connection timeouts. Increase TCP keepalive settings on both client and server (e.g., net.ipv4.tcp_keepalive_time=600).

中文步骤

  1. Configure the server to handle graceful shutdown and increase idle timeout. Example in Go: server := grpc.NewServer(grpc.KeepaliveParams(keepalive.ServerParameters{MaxConnectionIdle: 5 * time.Minute}))
  2. Use a connection pool with retry logic. In Python, use grpc.aio with automatic reconnection: channel = grpc.aio.insecure_channel('localhost:50051'); await channel.channel_ready()
  3. Check firewall or load balancer settings for idle connection timeouts. Increase TCP keepalive settings on both client and server (e.g., net.ipv4.tcp_keepalive_time=600).

Dead Ends

Common approaches that don't work:

  1. 80% fail

    Connection reset is not a timeout issue; longer timeouts won't prevent the peer from resetting the connection.

  2. 70% fail

    TLS is not the cause; disabling it reduces security without fixing the reset.

  3. 85% fail

    The server or network issue persists; client restart doesn't address the root cause.