grpc/grpc-java · error · UnsupportedOperationException

Unsupported operation getKeepAlive()

Error message

Unsupported operation getKeepAlive()

What it means

UdsSocket wraps Android LocalSocket, whose options differ from TCP sockets. TCP keep-alive has no equivalent configurable on the LocalSocket path used here, so getKeepAlive() throws UnsupportedOperationException by design. This is part of UdsSocket's pattern of rejecting unsupported java.net.Socket option accessors.

Source

Thrown at android/src/main/java/io/grpc/android/UdsSocket.java:113

  @Override
  public InetAddress getInetAddress() {
    throw new UnsupportedOperationException("getInetAddress() not supported");
  }

  @Override
  public InputStream getInputStream() throws IOException {
    return new FilterInputStream(localSocket.getInputStream()) {
      @Override
      public void close() throws IOException {
        UdsSocket.this.close();
      }
    };
  }

  @Override
  public boolean getKeepAlive() {
    throw new UnsupportedOperationException("Unsupported operation getKeepAlive()");
  }

  @Override
  public InetAddress getLocalAddress() {
    throw new UnsupportedOperationException("Unsupported operation getLocalAddress()");
  }

  @Override
  public int getLocalPort() {
    throw new UnsupportedOperationException("Unsupported operation getLocalPort()");
  }

  @Override
  public SocketAddress getLocalSocketAddress() {
    return new SocketAddress() {};
  }

  @Override

View on GitHub (pinned to 64daddc1f3)

Solutions

  1. Do not read or write TCP socket options on UDS sockets; rely on gRPC's own keepalive settings (ManagedChannelBuilder.keepAliveTime) at the channel level instead.
  2. Guard option reads with a class check for UdsSocket and skip them for UDS transport.
  3. Catch UnsupportedOperationException around option access if generic socket-handling code must remain shared.

Example fix

// before
boolean ka = socket.getKeepAlive();
// after
boolean ka = socket.getClass().getSimpleName().equals("UdsSocket")
    ? false
    : socket.getKeepAlive();
// gRPC-level keepalive instead:
// builder.keepAliveTime(30, TimeUnit.SECONDS)
Defensive patterns

Strategy: type-guard

Type guard

static boolean supportsTcpOptions(Socket s) {
  return !s.getClass().getName().equals("io.grpc.android.UdsSocket");
}

Try / catch

try {
  boolean ka = socket.getKeepAlive();
} catch (UnsupportedOperationException e) {
  // UDS socket: rely on gRPC channel-level keepAliveTime instead
}

Prevention

When it happens

Trigger: Calling getKeepAlive() on the UdsSocket instance from UdsSocketFactory — e.g. framework code that reads back socket options after connect, or pooling/health-check logic reading keep-alive state.

Common situations: HTTP connection pool code that inspects keep-alive settings; libraries ported from TCP contexts that unconditionally read socket options; Android network-health instrumentation.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


AI-assisted analysis of grpc/grpc-java@64daddc1f3 (2026-09-08). Data as JSON: /api/errors/8f5c0cc723c53a2c. Report an issue: GitHub.