grpc/grpc-java · info · UnsupportedOperationException

Unsupported operation setReuseAddress()

Error message

Unsupported operation setReuseAddress()

What it means

Sentinel guard in UdsSocket's Socket adapter: the SO_REUSEADDR option is not supported by the underlying LocalSocket for Unix domain sockets, so the setReuseAddress override throws unconditionally. It fires when generic socket setup code attempts to enable address reuse on this UDS wrapper.

Solutions

  1. Remove setReuseAddress for UDS sockets; SO_REUSEADDR does not apply
  2. If the UDS socket file lingers and blocks rebinding, delete the stale socket file before binding instead of using SO_REUSEADDR
  3. Make bootstrap code conditional on socket type

Example fix

// before
socket.setReuseAddress(true);
// after
if (!(socket instanceof io.grpc.android.UdsSocket)) {
  socket.setReuseAddress(true);
} else {
  java.io.File f = new java.io.File(udsPath);
  if (f.exists()) f.delete(); // stale socket file cleanup
}
Defensive patterns

Strategy: validation

Validate before calling

if (socket instanceof io.grpc.android.UdsSocket) { new java.io.File(udsPath).exists(); /* clean stale file instead */ return; }

Type guard

static boolean supportsReuseAddress(java.net.Socket s) { return !(s instanceof io.grpc.android.UdsSocket); }

Try / catch

try { socket.setReuseAddress(on); } catch (UnsupportedOperationException e) { /* UDS: handle stale socket file at bind time */ }

Prevention

When it happens

Trigger: Calling UdsSocket.setReuseAddress(boolean) directly, or server/listener bootstrap code that sets SO_REUSEADDR on every socket before binding (typical for TCP servers).

Common situations: Reusing TCP server-socket setup code for a UDS listener; 'address already in use' workarounds applied blindly to UDS sockets.

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/e2fb8363020cf306. Report an issue: GitHub.

Appendix: source

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

  }

  @Override
  public void setPerformancePreferences(int connectionTime, int latency, int bandwidth) {
    throw new UnsupportedOperationException("Unsupported operation setPerformancePreferences()");
  }

  @Override
  public void setReceiveBufferSize(int size) throws SocketException {
    try {
      localSocket.setReceiveBufferSize(size);
    } catch (IOException e) {
      throw toSocketException(e);
    }
  }

  @Override
  public void setReuseAddress(boolean on) {
    throw new UnsupportedOperationException("Unsupported operation setReuseAddress()");
  }

  @Override
  public void setSendBufferSize(int size) throws SocketException {
    try {
      localSocket.setSendBufferSize(size);
    } catch (IOException e) {
      throw toSocketException(e);
    }
  }

  @Override
  public void setSoLinger(boolean on, int linger) {
    throw new UnsupportedOperationException("Unsupported operation setSoLinger()");
  }

  @Override
  public void setSoTimeout(int timeout) throws SocketException {

View on GitHub (pinned to 64daddc1f3)