redis/jedis · error · JedisException
DISCARD command failed. Received response
Error message
DISCARD command failed. Received response: ${status} What it means
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.
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.
Example fix
// before
} catch (Exception e) {
t.discard(); // may throw JedisException on desynced conn
}
// after
} catch (Exception e) {
try {
t.discard();
} catch (JedisException de) {
connection.close(); // reset state on fresh reconnect
}
throw e;
} Defensive patterns
Strategy: try-catch
Try / catch
try {
transaction.discard();
} catch (JedisException e) {
// non-OK DISCARD reply: connection state is suspect
connection.close();
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "invalid response format", "malformed payload", "missing data field": when an API returns 200 but the response shape is wrong — this error's family across 23 libraries.
Related errors
- MULTI command failed. Received response:
- DISCARD without MULTI
- DISCARD without MULTI
- Cannot use Jedis when in Multi. Please use Transaction or…
- It is not allowed to create Transaction from this
AI-assisted analysis of redis/jedis@6dac31d4c2 (2026-09-08).
Data as JSON: /api/errors/58164909ed1e84b4.
Report an issue: GitHub.
Appendix: source
Thrown at src/main/java/redis/clients/jedis/ReliableTransaction.java:208
inMulti = false;
inWatch = false;
pipelinedResponses.clear();
}
}
@Override
public String discard() {
if (!inMulti) {
throw new IllegalStateException("DISCARD without MULTI");
}
try {
// processPipelinedResponses(pipelinedResponses.size());
// do nothing
connection.sendCommand(DISCARD);
String status = connection.getStatusCodeReply();
if (!"OK".equals(status)) {
throw new JedisException("DISCARD command failed. Received response: " + status);
}
return status;
} catch (JedisConnectionException jce) {
broken = true;
throw jce;
} finally {
inMulti = false;
inWatch = false;
pipelinedResponses.clear();
}
}
}
View on GitHub (pinned to 6dac31d4c2)