{"record":{"id":"f2854665c38e8259","repo":"grpc/grpc-java","slug":"unsupported-operation-setkeepalive","errorCode":null,"errorMessage":"Unsupported operation setKeepAlive()","messagePattern":"Unsupported operation setKeepAlive\\(\\)","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"info","filePath":"android/src/main/java/io/grpc/android/UdsSocket.java","lineNumber":235,"sourceCode":"\n  @Override\n  public synchronized boolean isInputShutdown() {\n    return inputShutdown;\n  }\n\n  @Override\n  public synchronized boolean isOutputShutdown() {\n    return outputShutdown;\n  }\n\n  @Override\n  public void sendUrgentData(int data) {\n    throw new UnsupportedOperationException(\"Unsupported operation sendUrgentData()\");\n  }\n\n  @Override\n  public void setKeepAlive(boolean on) {\n    throw new UnsupportedOperationException(\"Unsupported operation setKeepAlive()\");\n  }\n\n  @Override\n  public void setOOBInline(boolean on) {\n    throw new UnsupportedOperationException(\"Unsupported operation setOOBInline()\");\n  }\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);","sourceCodeStart":217,"sourceCodeEnd":253,"githubUrl":"https://github.com/grpc/grpc-java/blob/64daddc1f3d1975670f769f3e97bde8b2ba32d25/android/src/main/java/io/grpc/android/UdsSocket.java#L217-L253","documentation":"setKeepAlive() controls TCP SO_KEEPALIVE, which does not exist for Unix domain sockets. UdsSocket's override throws UnsupportedOperationException because the wrapped Android LocalSocket cannot honor it.","triggerScenarios":"Calling UdsSocket.setKeepAlive(true/false) directly, or shared channel/socket configuration code that enables keep-alive on every socket it touches (common with gRPC keepalive setups).","commonSituations":"Configuring gRPC TCP keepalive parameters (keepAliveTime/keepAliveTimeout) and additionally poking the raw socket; copying TCP channel setup code to a 'uds:' channel.","solutions":["Remove setKeepAlive calls for UDS channels — gRPC keepalive is configured on the channel/ClientCall, not the raw socket, and TCP keepalive does not apply to UDS","Use gRPC's built-in keepalive channel options if liveness detection is needed","Guard shared socket-config code to skip keep-alive for UdsSocket instances"],"exampleFix":"// before\nsocket.setKeepAlive(true);\n// after\nif (!(socket instanceof io.grpc.android.UdsSocket)) {\n  socket.setKeepAlive(true);\n}","handlingStrategy":"try-catch","validationCode":"boolean supportsKeepAlive = !(socket instanceof io.grpc.android.UdsSocket);","typeGuard":"static boolean supportsTcpKeepAlive(java.net.Socket s) { return !(s instanceof io.grpc.android.UdsSocket); }","tryCatchPattern":"try { socket.setKeepAlive(on); } catch (UnsupportedOperationException e) { /* not applicable on UDS */ }","preventionTips":["Configure keepalive via ManagedChannelBuilder keepAliveTime/keepAliveTimeout, not raw socket options","Branch socket configuration on transport type (TCP vs UDS)"],"tags":["grpc","android","unix-domain-socket","keepalive"],"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"}