{"record":{"id":"851cf4f6aabdb239","repo":"apache/cassandra","slug":"artificial-latency-limit-is-nanolimit-ns-tried","errorCode":null,"errorMessage":"Artificial latency limit is ${nanoLimit}ns; tried to set ${nanos}ns","messagePattern":"Artificial latency limit is (.+?)ns; tried to set (.+?)ns","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/net/ArtificialLatency.java","lineNumber":309,"sourceCode":"    }\n\n    public static void setArtificialLatencies(String latencies)\n    {\n        setArtificialLatencies(latencies, parseNanos(ARTIFICIAL_LATENCY_LIMIT.getString()));\n    }\n\n    public static void unsafeSetArtificialLatencies(String latencies)\n    {\n        setArtificialLatencies(latencies, Long.MAX_VALUE);\n    }\n\n    private static synchronized void setArtificialLatencies(String latencies, long nanoLimit)\n    {\n        if (latencies.indexOf(',') < 0)\n        {\n            long nanos = parseNanos(latencies);\n            if (nanos >= nanoLimit)\n                throw new IllegalArgumentException(\"Artificial latency limit is \" + nanoLimit + \"ns; tried to set \" + nanos + \"ns\");\n            artificialLatencyNanos = ignore -> nanos;\n        }\n        else\n        {\n            String[] parse = latencies.split(\",\");\n            Object2LongHashMap<String> dcLatencies = new Object2LongHashMap<>(-1L);\n            for (int i = 0 ; i < parse.length ; ++i)\n            {\n                String[] subparse = parse[i].split(\":\");\n                String dc = subparse[0];\n                long nanos = parseNanos(subparse[1]);\n                if (nanos >= nanoLimit)\n                    throw new IllegalArgumentException(\"Artificial latency limit is \" + nanoLimit + \"ns; tried to set \" + nanos + \"ns\");\n                dcLatencies.put(dc, nanos);\n            }\n            artificialLatencyNanos = addr -> {\n                Directory directory = ClusterMetadata.current().directory;\n                NodeId nodeId = directory.peerId(addr);","sourceCodeStart":291,"sourceCodeEnd":327,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/net/ArtificialLatency.java#L291-L327","documentation":"ArtificialLatency.setArtificialLatencies enforces an upper bound on configured artificial latencies (nanoLimit, e.g. from the artificial latency limit config) to prevent accidentally huge message delays. When a single (non-per-DC) latency value parses to nanos >= nanoLimit, an IllegalArgumentException is thrown reporting both the limit and the attempted value.","triggerScenarios":"Calling setArtificialLatencies with a single latency string whose millisecond value converts to nanoseconds greater than or equal to the configured nanoLimit (e.g. setting several seconds when the allowed maximum is well below that).","commonSituations":"Misconfigured test_latency/artificial latency in cassandra.yaml (comma expected but absent, so whole string treated as one value); trying to simulate multi-second delays exceeding the safety limit; confusion between ms and ns units leading to oversized values.","solutions":["Lower the configured latency so it is below the reported nanoLimit","If a larger value is genuinely needed, raise the artificial latency limit setting (test.jupiter.limit or equivalent advanced config) before calling setArtificialLatencies","Check for missing commas if intending per-DC latencies — a malformed per-DC string is parsed as a single oversized value","Convert units carefully: the limit is in nanoseconds, the input in milliseconds"],"exampleFix":"// before (limit is 1000000ns)\nArtificialLatency.setArtificialLatencies(\"5ms\"); // 5,000,000ns >= limit\n\n// after\nArtificialLatency.setArtificialLatencies(\"0.5ms\"); // 500,000ns < limit\n","handlingStrategy":"validation","validationCode":"long nanos = TimeUnit.MILLISECONDS.toNanos(Long.parseLong(latency.replace(\"ms\",\"\")));\nif (nanos >= nanoLimit) throw new Error(\"Latency \" + nanos + \"ns exceeds limit \" + nanoLimit + \"ns\");","typeGuard":null,"tryCatchPattern":"try { ArtificialLatency.setArtificialLatencies(latencies); }\ncatch (IllegalArgumentException e) { logger.error(\"Latency above allowed limit: {}\", e.getMessage()); }","preventionTips":["Check the configured artificial latency limit before setting values","Remember the limit is in nanoseconds while input is milliseconds","Validate per-DC strings have correct comma/colon structure so values parse as intended"],"tags":["configuration","latency","value-out-of-range"],"backgroundTag":"value-out-of-range","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}