elastic/elasticsearch · error · IllegalArgumentException

geoip max cache size must be 0 or greater

Error message

geoip max cache size must be 0 or greater

What it means

Thrown by the GeoIpCache constructor when maxSize is negative. The cache backs the geoip lookup results per (project, ip, databasePath); zero is allowed (no caching), negatives are not. IllegalArgumentException surfaces during cache construction, typically from a bad setting parse.

Source

Thrown at modules/ip-location/src/main/java/org/elasticsearch/ingest/geoip/GeoIpCache.java:53

     * something not being in the cache because the data doesn't exist in the database.
     */
    // visible for testing
    static final Object NO_RESULT = new Object() {
        @Override
        public String toString() {
            return "NO_RESULT";
        }
    };

    private final Cache<CacheKey, Object> cache;
    private final LongSupplier relativeNanoTimeProvider;
    private final LongAdder hitsTimeInNanos = new LongAdder();
    private final LongAdder missesTimeInNanos = new LongAdder();

    // package private for testing
    GeoIpCache(long maxSize, LongSupplier relativeNanoTimeProvider) {
        if (maxSize < 0) {
            throw new IllegalArgumentException("geoip max cache size must be 0 or greater");
        }
        this.relativeNanoTimeProvider = relativeNanoTimeProvider;
        this.cache = CacheBuilder.<CacheKey, Object>builder().setMaximumWeight(maxSize).build();
    }

    GeoIpCache(long maxSize) {
        this(maxSize, System::nanoTime);
    }

    @SuppressWarnings("unchecked")
    <RESPONSE> RESPONSE putIfAbsent(ProjectId projectId, String ip, String databasePath, Function<String, RESPONSE> retrieveFunction) {
        // can't use cache.computeIfAbsent due to the elevated permissions for the jackson (run via the cache loader)
        CacheKey cacheKey = new CacheKey(projectId, ip, databasePath);
        long cacheStart = relativeNanoTimeProvider.getAsLong();
        // intentionally non-locking for simplicity...it's OK if we re-put the same key/value in the cache during a race condition.
        Object response = cache.get(cacheKey);
        long cacheRequestTime = relativeNanoTimeProvider.getAsLong() - cacheStart;

View on GitHub (pinned to db6a809a66)

Solutions

  1. Set the cache size setting to 0 or a positive integer.
  2. Find the setting feeding maxSize and validate its parsed value before construction.
  3. If this fires from internal code, ensure no subtraction can underflow into a negative.
Defensive patterns

Strategy: validation

Validate before calling

long sanitizeCacheSize(long v) {
    if (v < 0) throw new IllegalArgumentException("geoip max cache size must be 0 or greater");
    return v;
}

Prevention

When it happens

Trigger: GeoIpCache(maxSize) or GeoIpCache(maxSize, nanoTimeProvider) called with maxSize < 0. Usually the maxSize originates from a geoip cache size setting that resolved to a negative number.

Common situations: A user setting cache.max_size to a negative value; an arithmetic/overflow that produces a negative; a default-value bug in a setting parser.

Related errors


AI-assisted analysis of elastic/elasticsearch@db6a809a66 (2026-08-12). Data as JSON: /api/errors/134c11926039b018. Report an issue: GitHub.