{"record":{"id":"b8c5f4198d35d900","repo":"microsoft/garnet","slug":"aofsizelimit-cannot-be-enforced-with-disabled-aof","errorCode":null,"errorMessage":"AofSizeLimit cannot be enforced with disabled AOF!","messagePattern":"AofSizeLimit cannot be enforced with disabled AOF!","errorType":"exception","errorClass":"GarnetException","httpStatus":null,"severity":"critical","filePath":"libs/host/Configuration/Options.cs","lineNumber":839,"sourceCode":"\n            // Warn users who explicitly opt into Scan compaction about the memory-spike cost.\n            // Scan builds a temporary parallel KV index proportional to the keyspace; Lookup is the recommended alternative.\n            if (CompactionType == LogCompactionType.Scan)\n            {\n                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.\");\n            }\n\n            if (SlowLogThreshold > 0)\n            {\n                if (SlowLogThreshold < 100)\n                    throw new Exception(\"SlowLogThreshold must be at least 100 microseconds.\");\n            }\n\n\n            if (!EnableAOF.GetValueOrDefault())\n            {\n                if (!string.IsNullOrEmpty(AofSizeLimit))\n                    throw new GarnetException(\"AofSizeLimit cannot be enforced with disabled AOF!\");\n            }\n\n            Func<INamedDeviceFactoryCreator> azureFactoryCreator = () =>\n            {\n                if (!string.IsNullOrEmpty(AzureStorageConnectionString))\n                {\n                    return new AzureStorageNamedDeviceFactoryCreator(AzureStorageConnectionString, logger);\n                }\n                var credential = new ChainedTokenCredential(\n                    new WorkloadIdentityCredential(),\n                    new ManagedIdentityCredential(clientId: AzureStorageManagedIdentity)\n                );\n                return new AzureStorageNamedDeviceFactoryCreator(AzureStorageServiceUri, credential, logger);\n            };\n\n            return new GarnetServerOptions(logger)\n            {\n                EndPoints = endpoints,","sourceCodeStart":821,"sourceCodeEnd":857,"githubUrl":"https://github.com/microsoft/garnet/blob/951b0fc6838721f89d102c2bbe1b914e8d39d700/libs/host/Configuration/Options.cs#L821-L857","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["If you want AOF with a size limit, set EnableAOF=true alongside AofSizeLimit.","If AOF is intentionally disabled, clear AofSizeLimit (set it to empty string or remove the config entry)."],"exampleFix":"// before\noptions.EnableAOF = false;\noptions.AofSizeLimit = \"64mb\";\n\n// after: enable AOF to enforce the limit\noptions.EnableAOF = true;\noptions.AofSizeLimit = \"64mb\";","handlingStrategy":"validation","validationCode":"void ValidateAofSizeLimitConsistency(bool enableAof, string aofSizeLimit)\n{\n    if (!enableAof && !string.IsNullOrEmpty(aofSizeLimit))\n        throw new InvalidOperationException(\"AofSizeLimit cannot be set when EnableAOF is false. Either enable AOF or clear the limit.\");\n}","typeGuard":null,"tryCatchPattern":"try\n{\n    options.Initialize(logger);\n}\ncatch (GarnetException ex) when (ex.Message.Contains(\"AofSizeLimit cannot be enforced\"))\n{\n    logger.LogError(\"AofSizeLimit set but AOF is disabled. Set EnableAOF=true or clear AofSizeLimit.\");\n    throw;\n}","preventionTips":["Keep EnableAOF and AofSizeLimit in the same config section so they are toggled together.","Run a config-consistency check at deploy time that flags AOF-related mismatches."],"tags":["config","aof","validation","mutual-exclusion","options","persistence"],"backgroundTag":null,"analyzedSha":"951b0fc6838721f89d102c2bbe1b914e8d39d700","analyzedAt":"2026-08-13T19:01:32.939Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}