{"record":{"id":"e2fb8363020cf306","repo":"grpc/grpc-java","slug":"unsupported-operation-setreuseaddress","errorCode":null,"errorMessage":"Unsupported operation setReuseAddress()","messagePattern":"Unsupported operation setReuseAddress\\(\\)","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"info","filePath":"android/src/main/java/io/grpc/android/UdsSocket.java","lineNumber":259,"sourceCode":"  }\n\n  @Override\n  public void setPerformancePreferences(int connectionTime, int latency, int bandwidth) {\n    throw new UnsupportedOperationException(\"Unsupported operation setPerformancePreferences()\");\n  }\n\n  @Override\n  public void setReceiveBufferSize(int size) throws SocketException {\n    try {\n      localSocket.setReceiveBufferSize(size);\n    } catch (IOException e) {\n      throw toSocketException(e);\n    }\n  }\n\n  @Override\n  public void setReuseAddress(boolean on) {\n    throw new UnsupportedOperationException(\"Unsupported operation setReuseAddress()\");\n  }\n\n  @Override\n  public void setSendBufferSize(int size) throws SocketException {\n    try {\n      localSocket.setSendBufferSize(size);\n    } catch (IOException e) {\n      throw toSocketException(e);\n    }\n  }\n\n  @Override\n  public void setSoLinger(boolean on, int linger) {\n    throw new UnsupportedOperationException(\"Unsupported operation setSoLinger()\");\n  }\n\n  @Override\n  public void setSoTimeout(int timeout) throws SocketException {","sourceCodeStart":241,"sourceCodeEnd":277,"githubUrl":"https://github.com/grpc/grpc-java/blob/64daddc1f3d1975670f769f3e97bde8b2ba32d25/android/src/main/java/io/grpc/android/UdsSocket.java#L241-L277","documentation":"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.","triggerScenarios":"Calling UdsSocket.setReuseAddress(boolean) directly, or server/listener bootstrap code that sets SO_REUSEADDR on every socket before binding (typical for TCP servers).","commonSituations":"Reusing TCP server-socket setup code for a UDS listener; 'address already in use' workarounds applied blindly to UDS sockets.","solutions":["Remove setReuseAddress for UDS sockets; SO_REUSEADDR does not apply","If the UDS socket file lingers and blocks rebinding, delete the stale socket file before binding instead of using SO_REUSEADDR","Make bootstrap code conditional on socket type"],"exampleFix":"// before\nsocket.setReuseAddress(true);\n// after\nif (!(socket instanceof io.grpc.android.UdsSocket)) {\n  socket.setReuseAddress(true);\n} else {\n  java.io.File f = new java.io.File(udsPath);\n  if (f.exists()) f.delete(); // stale socket file cleanup\n}","handlingStrategy":"validation","validationCode":"if (socket instanceof io.grpc.android.UdsSocket) { new java.io.File(udsPath).exists(); /* clean stale file instead */ return; }","typeGuard":"static boolean supportsReuseAddress(java.net.Socket s) { return !(s instanceof io.grpc.android.UdsSocket); }","tryCatchPattern":"try { socket.setReuseAddress(on); } catch (UnsupportedOperationException e) { /* UDS: handle stale socket file at bind time */ }","preventionTips":["For UDS rebinding problems, delete a stale socket file before bind rather than using SO_REUSEADDR","Keep server bootstrap code transport-aware"],"tags":["grpc","android","unix-domain-socket","socket-options"],"backgroundTag":"unsupported-operation","analyzedSha":"64daddc1f3d1975670f769f3e97bde8b2ba32d25","analyzedAt":"2026-09-08T06:14:57.704Z","contentChangedAt":"2026-09-08T06:14:57.704Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}