{"record":{"id":"58164909ed1e84b4","repo":"redis/jedis","slug":"discard-command-failed-received-response-statu","errorCode":null,"errorMessage":"DISCARD command failed. Received response: ${status}","messagePattern":"DISCARD command failed\\. Received response: (.+?)","errorType":"exception","errorClass":"JedisException","httpStatus":null,"severity":"error","filePath":"src/main/java/redis/clients/jedis/ReliableTransaction.java","lineNumber":208,"sourceCode":"      inMulti = false;\n      inWatch = false;\n      pipelinedResponses.clear();\n    }\n  }\n\n  @Override\n  public String discard() {\n    if (!inMulti) {\n      throw new IllegalStateException(\"DISCARD without MULTI\");\n    }\n\n    try {\n      // processPipelinedResponses(pipelinedResponses.size());\n      // do nothing\n      connection.sendCommand(DISCARD);\n      String status = connection.getStatusCodeReply();\n      if (!\"OK\".equals(status)) {\n        throw new JedisException(\"DISCARD command failed. Received response: \" + status);\n      }\n      return status;\n    } catch (JedisConnectionException jce) {\n      broken = true;\n      throw jce;\n    } finally {\n      inMulti = false;\n      inWatch = false;\n      pipelinedResponses.clear();\n    }\n  }\n}\n","sourceCodeStart":190,"sourceCodeEnd":221,"githubUrl":"https://github.com/redis/jedis/blob/6dac31d4c224fb3257c216f3985340c6f500cdcb/src/main/java/redis/clients/jedis/ReliableTransaction.java#L190-L221","documentation":"After sending DISCARD, ReliableTransaction expects the server's +OK status reply. Any other reply throws JedisException('DISCARD command failed. Received response: <status>'). This signals the server did not confirm transaction cancellation — usually because the connection state desynced or the reply was actually an error.","triggerScenarios":"Calling discard() on a connection whose reply stream is desynced (prior unread errors), a server erroring on DISCARD (e.g. NOAUTH/ACL or proxy interference), or a mid-failover connection returning an unexpected status.","commonSituations":"Pooled connections with leftover replies from aborted reads; Redis proxies/meshes that rewrite MULTI/DISCARD; discarding during network degradation where error replies replace status replies.","solutions":["Inspect the status text in the message; treat non-OK replies as connection corruption and close/reconnect the connection.","Avoid reusing pooled connections that may have unread replies; use a dedicated connection for transactions.","Retry the cleanup on a fresh connection; the transaction is server-side aborted anyway if the connection drops."],"exampleFix":"// before\n} catch (Exception e) {\n  t.discard(); // may throw JedisException on desynced conn\n}\n\n// after\n} catch (Exception e) {\n  try {\n    t.discard();\n  } catch (JedisException de) {\n    connection.close(); // reset state on fresh reconnect\n  }\n  throw e;\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  transaction.discard();\n} catch (JedisException e) {\n  // non-OK DISCARD reply: connection state is suspect\n  connection.close();\n}","preventionTips":["Close connections that return unexpected status replies instead of returning them to the pool.","Use dedicated (non-pooled) connections for transaction lifecycles.","Check for intermediaries (proxies, service mesh) rewriting transaction commands."],"tags":["transaction","discard","redis-protocol"],"backgroundTag":"unexpected-api-response-shape","analyzedSha":"6dac31d4c224fb3257c216f3985340c6f500cdcb","analyzedAt":"2026-09-08T04:55:01.204Z","contentChangedAt":"2026-09-08T04:55:01.204Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}