{"record":{"id":"9ad91fd85c3a5e00","repo":"apache/hadoop","slug":"maxretries-maxretries-long-size-1","errorCode":null,"errorMessage":"maxRetries = ${maxRetries} >= ${Long.SIZE - 1}","messagePattern":"maxRetries = (.+?) >= (.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/retry/RetryPolicies.java","lineNumber":635,"sourceCode":"      if (policy == null) {\n        policy = defaultPolicy;\n      }\n      return policy.shouldRetry(\n          e, retries, failovers, isIdempotentOrAtMostOnce);\n    }\n  }\n\n  static class ExponentialBackoffRetry extends RetryLimited {\n    \n    public ExponentialBackoffRetry(\n        int maxRetries, long sleepTime, TimeUnit timeUnit) {\n      super(maxRetries, sleepTime, timeUnit);\n\n      if (maxRetries < 0) {\n        throw new IllegalArgumentException(\"maxRetries = \" + maxRetries + \" < 0\");\n      } else if (maxRetries >= Long.SIZE - 1) {\n        //calculateSleepTime may overflow. \n        throw new IllegalArgumentException(\"maxRetries = \" + maxRetries\n            + \" >= \" + (Long.SIZE - 1));\n      }\n    }\n    \n    @Override\n    protected long calculateSleepTime(int retries) {\n      return calculateExponentialTime(sleepTime, retries + 1);\n    }\n\n  }\n  \n  /**\n   * Fail over and retry in the case of:\n   *   Remote StandbyException (server is up, but is not the active server)\n   *   Immediate socket exceptions (e.g. no route to host, econnrefused)\n   *   Socket exceptions after initial connection when operation is idempotent\n   * \n   * The first failover is immediate, while all subsequent failovers wait an","sourceCodeStart":617,"sourceCodeEnd":653,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/retry/RetryPolicies.java#L617-L653","documentation":"ExponentialBackoffRetry computes sleeps via calculateExponentialTime (shift-style exponentials on sleepTime). With maxRetries >= Long.SIZE - 1 (63), the shift can overflow a long and produce negative or nonsensical delays, so the constructor rejects such counts up front. This is an overflow guard, not an opinion about good retry counts — though 63 exponential retries already spans astronomical time.","triggerScenarios":"Configuring exponential backoff with maxRetries >= 63 — commonly someone 'disabling the cap' with Integer.MAX_VALUE, 999, or a value copied from a recipe tuned for a framework that allows unbounded counts.","commonSituations":"Operators emulating 'retry forever' with a huge count; copied exponential-backoff configs from other libraries; generated configs with sentinel values like 2^31-1.","solutions":["Cap maxRetries below 63 — 10 to 20 is already generous for exponential backoff.","For effectively-unlimited retries over time, use a time-bounded policy such as RetryUpToMaximumTimeWithFixedSleep instead of a huge count.","Sanity-check the total sleep the schedule implies (sleepTime * 2^maxRetries) — if it exceeds your operational patience, shrink the count."],"exampleFix":"// before\nnew ExponentialBackoffRetry(999, 1000, TimeUnit.MILLISECONDS);\n\n// after\nint maxRetries = Math.min(conf.getInt(\"my.retries\", 10), 62);\nnew ExponentialBackoffRetry(maxRetries, 1000, TimeUnit.MILLISECONDS);","handlingStrategy":"validation","validationCode":"int maxRetries = conf.getInt(\"my.exp.retries\", 10);\nif (maxRetries >= Long.SIZE - 1) {\n  throw new IllegalArgumentException(\n      \"exponential backoff maxRetries must be < 63, got \" + maxRetries);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Cap exponential retry counts well below 63 (10-20 is ample).","Use time-bounded policies for long-running retry needs instead of huge counts.","Reject sentinel values like Integer.MAX_VALUE in config linting for retry knobs."],"tags":["retry-policy","configuration","overflow","exponential-backoff"],"backgroundTag":"invalid-config-value","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}