{"record":{"id":"86613a5fd0477d5a","repo":"apache/shenyu","slug":"decrement-when-domain-ssl-counts-0-an-unknown-exception-has","errorCode":null,"errorMessage":"Decrement when domain ssl counts <= 0, an unknown exception has occurred.","messagePattern":"Decrement when domain ssl counts <= 0, an unknown exception has occurred\\.","errorType":"exception","errorClass":"ShenyuException","httpStatus":null,"severity":"error","filePath":"shenyu-kubernetes-controller/src/main/java/org/apache/shenyu/k8s/cache/IngressSecretCache.java","lineNumber":118,"sourceCode":"     * @return the previous number of the ingress that enables the domain name to take effect\n     */\n    public Integer getAndIncrementDomainNums(final String domain) {\n        AtomicInteger count = DOMAIN_NUMS_MAP.computeIfAbsent(domain, k -> new AtomicInteger(0));\n        return count.getAndIncrement();\n    }\n\n    /**\n     * Get and decrement the number of the ingress that enables the domain name to take effect.\n     *\n     * @param domain tls domain\n     * @return the previous number of the ingress that enables the domain name to take effect\n     */\n    public Integer getAndDecrementDomainNums(final String domain) {\n        AtomicInteger count = DOMAIN_NUMS_MAP.computeIfAbsent(domain, k -> new AtomicInteger(0));\n        if (count.intValue() > 0) {\n            return count.getAndDecrement();\n        }\n        throw new ShenyuException(\"Decrement when domain ssl counts <= 0, an unknown exception has occurred.\");\n    }\n\n    private String getKey(final String namespace, final String name) {\n        return namespace + \"-\" + name;\n    }\n}\n","sourceCodeStart":100,"sourceCodeEnd":125,"githubUrl":"https://github.com/apache/shenyu/blob/567142e07261b3e615ae8850b30f4421f455cc5d/shenyu-kubernetes-controller/src/main/java/org/apache/shenyu/k8s/cache/IngressSecretCache.java#L100-L125","documentation":"IngressSecretCache.getAndDecrementDomainNums decrements the reference count of domains using an SSL secret. If the count is already <= 0 there is nothing to decrement, indicating the internal bookkeeping is out of sync (decrement without a matching increment), so it throws ShenyuException. This is an internal invariant violation in the k8s controller cache.","triggerScenarios":"Calling getAndDecrementDomainNums(domain) when DOMAIN_NUMS_MAP has no positive count for that domain — e.g. delete/reconcile events arriving out of order, or double removal of a domain reference.","commonSituations":"Kubernetes events processed concurrently or re-delivered, an Ingress delete handled twice, a bug in increment pairing after controller restarts with a warm map.","solutions":["Audit the increment/decrement call sites so every decrement is paired with exactly one prior increment","Reset/rebuild the cache from current Ingress/Secret state (controller restart) to resync counts","Log the domain and map state when this occurs and skip the decrement instead of crashing reconciliation","Check for duplicate or out-of-order k8s event handling in the controller"],"exampleFix":"// before\nif (count.intValue() > 0) { return count.getAndDecrement(); }\n// defensively, callers should check first:\n// after\nif (cache.getDomainNums(domain) > 0) { cache.getAndDecrementDomainNums(domain); }","handlingStrategy":"validation","validationCode":"if (cache.getDomainNums(domain) > 0) {\n    cache.getAndDecrementDomainNums(domain);\n}","typeGuard":null,"tryCatchPattern":"try {\n    cache.getAndDecrementDomainNums(domain);\n} catch (ShenyuException e) {\n    log.warn(\"decrement underflow for domain {} - rebuilding cache\", domain, e);\n    cache.rebuildFromClusterState();\n}","preventionTips":["Pair every increment with exactly one decrement","Handle k8s delete events idempotently","Rebuild counts from cluster state on controller restart","Log map state on underflow to diagnose event ordering"],"tags":["kubernetes","cache","state"],"backgroundTag":"internal-invariant-violation","analyzedSha":"567142e07261b3e615ae8850b30f4421f455cc5d","analyzedAt":"2026-09-12T10:08:21.293Z","contentChangedAt":"2026-09-12T10:08:21.293Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}