{"record":{"id":"044a5c27b4abefb1","repo":"grpc/grpc-java","slug":"unsupported-operation-setsolinger","errorCode":null,"errorMessage":"Unsupported operation setSoLinger()","messagePattern":"Unsupported operation setSoLinger\\(\\)","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"info","filePath":"android/src/main/java/io/grpc/android/UdsSocket.java","lineNumber":273,"sourceCode":"  }\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 {\n    try {\n      localSocket.setSoTimeout(timeout);\n    } catch (IOException e) {\n      throw toSocketException(e);\n    }\n  }\n\n  @Override\n  public void setTcpNoDelay(boolean on) {\n    // no-op\n  }\n\n  @Override\n  public void setTrafficClass(int tc) {","sourceCodeStart":255,"sourceCodeEnd":291,"githubUrl":"https://github.com/grpc/grpc-java/blob/64daddc1f3d1975670f769f3e97bde8b2ba32d25/android/src/main/java/io/grpc/android/UdsSocket.java#L255-L291","documentation":"setSoLinger() configures TCP SO_LINGER behavior on close (block until unsent data is flushed or discarded after N seconds). Unix domain sockets do not support this option, so UdsSocket throws UnsupportedOperationException.","triggerScenarios":"Direct call to UdsSocket.setSoLinger(boolean,int), or connection-teardown tuning code that sets linger on all sockets it manages.","commonSituations":"Applying aggressive-close/linger tuning (e.g. setSoLinger(true, 0)) from TCP experience to a UDS gRPC channel; shared socket factory classes.","solutions":["Remove the setSoLinger call for UDS channels; close semantics are handled by the LocalSocket/stream layer","Centralize socket-option setting in one type-aware helper that skips TCP-only options","Catch UnsupportedOperationException around option setting so cleanup paths don't fail"],"exampleFix":"// before\nsocket.setSoLinger(true, 0); // hard close\n// after\nif (socket.getClass() != io.grpc.android.UdsSocket.class) {\n  socket.setSoLinger(true, 0);\n}","handlingStrategy":"try-catch","validationCode":"boolean supportsLinger = !(socket instanceof io.grpc.android.UdsSocket);","typeGuard":"static boolean supportsSoLinger(java.net.Socket s) { return !(s instanceof io.grpc.android.UdsSocket); }","tryCatchPattern":"try { socket.setSoLinger(on, linger); } catch (UnsupportedOperationException e) { /* not applicable on UDS */ }","preventionTips":["Do not carry TCP close/linger tuning into UDS channels","Consolidate option setting in a single guarded helper"],"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"}