{"record":{"id":"e49cf8f9104508f5","repo":"grpc/grpc-java","slug":"unsupported-operation-settrafficclass","errorCode":null,"errorMessage":"Unsupported operation setTrafficClass()","messagePattern":"Unsupported operation setTrafficClass\\(\\)","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"info","filePath":"android/src/main/java/io/grpc/android/UdsSocket.java","lineNumber":292,"sourceCode":"  }\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) {\n    throw new UnsupportedOperationException(\"Unsupported operation setTrafficClass()\");\n  }\n\n  @Override\n  public synchronized void shutdownInput() throws IOException {\n    localSocket.shutdownInput();\n    inputShutdown = true;\n  }\n\n  @Override\n  public synchronized void shutdownOutput() throws IOException {\n    localSocket.shutdownOutput();\n    outputShutdown = true;\n  }\n\n  private static SocketException toSocketException(Throwable e) {\n    SocketException se = new SocketException();\n    se.initCause(e);\n    return se;","sourceCodeStart":274,"sourceCodeEnd":310,"githubUrl":"https://github.com/grpc/grpc-java/blob/64daddc1f3d1975670f769f3e97bde8b2ba32d25/android/src/main/java/io/grpc/android/UdsSocket.java#L274-L310","documentation":"setTrafficClass() writes the IP_TOS/DSCP marking for IP packets, which is inapplicable to Unix domain sockets where no IP header exists. UdsSocket throws UnsupportedOperationException to make this explicit.","triggerScenarios":"Calling UdsSocket.setTrafficClass(int) directly, or QoS/network-policy code that marks traffic (IPTOS_LOWCOST/THROUGHPUT/RELIABILITY) on every socket.","commonSituations":"Enterprise Android apps applying DSCP markings for network policy to all channels; copy-pasted TCP channel configuration used with 'uds:' targets.","solutions":["Do not set traffic class on UDS sockets — packets never traverse an IP network","Apply QoS marking only on TCP/UDP channels; keep it out of UDS channel setup","Handle or skip UnsupportedOperationException when applying option sets generically"],"exampleFix":"// before\nsocket.setTrafficClass(0x10); // IPTOS_LOWCOST\n// after\nif (!(socket instanceof io.grpc.android.UdsSocket)) {\n  socket.setTrafficClass(0x10);\n}","handlingStrategy":"validation","validationCode":"boolean canMarkTraffic = !(socket instanceof io.grpc.android.UdsSocket);","typeGuard":"static boolean supportsTrafficClass(java.net.Socket s) { return !(s instanceof io.grpc.android.UdsSocket); }","tryCatchPattern":"try { socket.setTrafficClass(tc); } catch (UnsupportedOperationException e) { /* no IP header on UDS */ }","preventionTips":["Restrict QoS/DSCP marking code to TCP/UDP transports","Audit shared network-policy modules when adding 'uds:' gRPC targets"],"tags":["grpc","android","unix-domain-socket","qos"],"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"}