microsoft/garnet · critical · GarnetException

AofSizeLimit cannot be enforced with disabled AOF!

Error message

AofSizeLimit cannot be enforced with disabled AOF!

What it means

GarnetException thrown during Options.Initialize when EnableAOF is false (or default) but AofSizeLimit is set to a non-empty value. The AOF size limit can only be enforced when the append-only file system is enabled; setting a limit without enabling AOF is contradictory and rejected at startup.

Source

Thrown at libs/host/Configuration/Options.cs:839

            // Warn users who explicitly opt into Scan compaction about the memory-spike cost.
            // Scan builds a temporary parallel KV index proportional to the keyspace; Lookup is the recommended alternative.
            if (CompactionType == LogCompactionType.Scan)
            {
                logger?.LogWarning("Compaction type Scan builds a temporary parallel KV index proportional to the keyspace, causing significant transient memory use. Use Lookup instead unless you have a specific reason for Scan.");
            }

            if (SlowLogThreshold > 0)
            {
                if (SlowLogThreshold < 100)
                    throw new Exception("SlowLogThreshold must be at least 100 microseconds.");
            }


            if (!EnableAOF.GetValueOrDefault())
            {
                if (!string.IsNullOrEmpty(AofSizeLimit))
                    throw new GarnetException("AofSizeLimit cannot be enforced with disabled AOF!");
            }

            Func<INamedDeviceFactoryCreator> azureFactoryCreator = () =>
            {
                if (!string.IsNullOrEmpty(AzureStorageConnectionString))
                {
                    return new AzureStorageNamedDeviceFactoryCreator(AzureStorageConnectionString, logger);
                }
                var credential = new ChainedTokenCredential(
                    new WorkloadIdentityCredential(),
                    new ManagedIdentityCredential(clientId: AzureStorageManagedIdentity)
                );
                return new AzureStorageNamedDeviceFactoryCreator(AzureStorageServiceUri, credential, logger);
            };

            return new GarnetServerOptions(logger)
            {
                EndPoints = endpoints,

View on GitHub (pinned to 951b0fc683)

Solutions

  1. If you want AOF with a size limit, set EnableAOF=true alongside AofSizeLimit.
  2. If AOF is intentionally disabled, clear AofSizeLimit (set it to empty string or remove the config entry).

Example fix

// before
options.EnableAOF = false;
options.AofSizeLimit = "64mb";

// after: enable AOF to enforce the limit
options.EnableAOF = true;
options.AofSizeLimit = "64mb";
Defensive patterns

Strategy: validation

Validate before calling

void ValidateAofSizeLimitConsistency(bool enableAof, string aofSizeLimit)
{
    if (!enableAof && !string.IsNullOrEmpty(aofSizeLimit))
        throw new InvalidOperationException("AofSizeLimit cannot be set when EnableAOF is false. Either enable AOF or clear the limit.");
}

Try / catch

try
{
    options.Initialize(logger);
}
catch (GarnetException ex) when (ex.Message.Contains("AofSizeLimit cannot be enforced"))
{
    logger.LogError("AofSizeLimit set but AOF is disabled. Set EnableAOF=true or clear AofSizeLimit.");
    throw;
}

Prevention

When it happens

Trigger: Setting --aof-size-limit (AofSizeLimit) in the config while not enabling --aof (EnableAOF). Happens when a user copies an AOF-enabled config but drops the EnableAOF flag, or when trying to pre-configure the limit before enabling AOF in a later deployment.

Common situations: Config template includes a size limit but EnableAOF was removed; staged rollout where AOF is disabled for testing but the limit field was left populated; misunderstanding that the limit requires AOF to be active.

Related errors


AI-assisted analysis of microsoft/garnet@951b0fc683 (2026-08-13). Data as JSON: /api/errors/b8c5f4198d35d900. Report an issue: GitHub.