{"record":{"id":"3999418df821585f","repo":"redis/jedis","slug":"server-status-code-reply","errorCode":null,"errorMessage":"<server status code reply>","messagePattern":"<server status code reply>","errorType":"exception","errorClass":"JedisException","httpStatus":null,"severity":"warning","filePath":"src/main/java/redis/clients/jedis/Jedis.java","lineNumber":3645,"sourceCode":"  @Override\n  public long lastsave() {\n    connection.sendCommand(LASTSAVE);\n    return connection.getIntegerReply();\n  }\n\n  /**\n   * Synchronously save the DB on disk, then shutdown the server.\n   * <p>\n   * Stop all the clients, save the DB, then quit the server. This commands makes sure that the DB\n   * is switched off without the lost of any data.\n   * @throws JedisException with the status code reply on error. On success nothing is thrown since\n   *         the server quits and the connection is closed.\n   */\n  @Override\n  public void shutdown() throws JedisException {\n    connection.sendCommand(SHUTDOWN);\n    try {\n      throw new JedisException(connection.getStatusCodeReply());\n    } catch (JedisConnectionException jce) {\n      // expected\n      connection.setBroken();\n    }\n  }\n\n  @Override\n  public void shutdown(ShutdownParams shutdownParams) throws JedisException {\n    connection.sendCommand(new CommandArguments(SHUTDOWN).addParams(shutdownParams));\n    try {\n      throw new JedisException(connection.getStatusCodeReply());\n    } catch (JedisConnectionException jce) {\n      // expected\n      connection.setBroken();\n    }\n  }\n\n  @Override","sourceCodeStart":3627,"sourceCodeEnd":3663,"githubUrl":"https://github.com/redis/jedis/blob/6dac31d4c224fb3257c216f3985340c6f500cdcb/src/main/java/redis/clients/jedis/Jedis.java#L3627-L3663","documentation":"SHUTDOWN normally closes the connection before a reply arrives, so shutdown() reads the status-code reply inside a try/catch for JedisConnectionException (expected). If a reply IS obtainable, it throws JedisException carrying the server's status text (e.g. an error because the server refused to shut down). The 'message' is thus whatever Redis returned.","triggerScenarios":"Calling jedis.shutdown() and the server responds with a status/error reply instead of dropping the connection — typically when the shutdown failed (e.g. save error with SHUTDOWN NOSAVE absent, or permission issues) so the connection stays open long enough for the reply to be read.","commonSituations":"Testing scripts that expect the connection to die immediately but Redis replies with an error and aborts shutdown; shutdown on a server configured with appendonly/save problems that refuse persistence; using shutdown against a managed service that disallows it.","solutions":["Expect JedisException on shutdown and treat any reply as informational; catch it around shutdown()","Check the server logs to see why SHUTDOWN did not complete","Use SHUTDOWN NOSAVE (ShutdownParams) when a failing save is blocking the shutdown","Verify you are allowed to run SHUTDOWN on that instance (managed services often block it)"],"exampleFix":"// before\njedis.shutdown(); // throws JedisException with server reply\n// after\ntry {\n  jedis.shutdown();\n} catch (JedisConnectionException expected) {\n  // normal: server closed the connection\n} catch (JedisException e) {\n  log.warn(\"SHUTDOWN returned: {}\", e.getMessage());\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  jedis.shutdown();\n} catch (JedisConnectionException expected) {\n  // normal: server closed the connection\n} catch (JedisException e) {\n  log.warn(\"SHUTDOWN server reply: {}\", e.getMessage());\n}","preventionTips":["Treat any exception from shutdown() as expected behavior, not a client bug","Prefer NOSAVE when persistence may be failing and data loss is acceptable","Confirm SHUTDOWN is permitted on managed instances before relying on it"],"tags":["shutdown","server-reply","jedis-exception","redis"],"backgroundTag":"api-error-response","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"}