{"record":{"id":"49c3c851073c2a3c","repo":"alibaba/nacos","slug":"30000-49c3c8","errorCode":"30000","errorMessage":"Meta cas failed","messagePattern":"Meta cas failed","errorType":"exception","errorClass":"NacosApiException","httpStatus":500,"severity":"critical","filePath":"ai/src/main/java/com/alibaba/nacos/ai/service/resource/AiResourceManager.java","lineNumber":151,"sourceCode":"                newValue)) {\n                return CasResult.SUCCESS;\n            }\n            AiResource latest = aiResourcePersistService.find(namespaceId, name, type);\n            if (latest == null || latest.getMetaVersion() == null) {\n                return CasResult.META_LOST;\n            }\n            expected = latest.getMetaVersion();\n            onConflictRefresh.accept(newValue, latest);\n        }\n        return CasResult.MAX_RETRIES;\n    }\n    \n    /**\n     * Translate a non-SUCCESS CasResult into the appropriate exception for strict callers.\n     */\n    private void handleStrictCasResult(CasResult result) throws NacosException {\n        if (result == CasResult.META_LOST) {\n            throw new NacosApiException(NacosException.SERVER_ERROR, ErrorCode.SERVER_ERROR,\n                \"Meta cas failed\");\n        }\n        if (result == CasResult.MAX_RETRIES) {\n            throw new NacosApiException(NacosException.CONFLICT, ErrorCode.RESOURCE_CONFLICT,\n                \"Meta update conflict, retry\");\n        }\n    }\n    \n    /**\n     * CAS-update the versionInfo field of a resource meta row.\n     */\n    public void updateVersionInfoCas(String namespaceId, AiResource meta, ResourceVersionInfo info)\n        throws NacosException {\n        if (meta == null || meta.getMetaVersion() == null) {\n            throw new NacosApiException(NacosException.SERVER_ERROR, ErrorCode.SERVER_ERROR,\n                \"Meta version missing\");\n        }\n        AiResource newValue = buildVersionInfoUpdateValue(meta, info);","sourceCodeStart":133,"sourceCodeEnd":169,"githubUrl":"https://github.com/alibaba/nacos/blob/9b989acdf181d00898f2e8839257bb2b2a3cefe3/ai/src/main/java/com/alibaba/nacos/ai/service/resource/AiResourceManager.java#L133-L169","documentation":"Thrown by handleStrictCasResult when doCasLoop returns CasResult.META_LOST — the resource meta row disappeared (became null or lost its metaVersion) during a retry iteration of the optimistic CAS loop. HTTP 500 SERVER_ERROR (code 30000). This indicates the resource was deleted concurrently while being updated.","triggerScenarios":"A CAS-based meta update (versionInfo, bizTags, description) is in its retry loop, and between a failed updateMetaCas and the subsequent find(), the resource is deleted. The retry re-fetch returns null, triggering META_LOST which handleStrictCasResult translates to this exception.","commonSituations":"Concurrent delete and update on the same resource; a cleanup/reaper process removes resources while a write is in-flight; manual database intervention deleting rows during active traffic.","solutions":["Verify the resource still exists before retrying the operation.","Investigate and eliminate concurrent delete operations on resources being updated.","If using a reaper/cleanup job, ensure it does not race with active mutations.","Reload the resource and retry the full operation if the delete was unintended."],"exampleFix":"// before: update races with a concurrent delete\nresourceManager.updateBizTagsCas(ns, meta, newTags); // meta deleted mid-loop\n\n// after: check existence, retry the whole operation\nAiResource fresh = resourceManager.findMeta(ns, name, type);\nif (fresh != null) {\n    resourceManager.updateBizTagsCas(ns, fresh, newTags);\n}","handlingStrategy":"retry","validationCode":"// Verify resource exists before CAS update\nAiResource meta = resourceManager.findMeta(ns, name, type);\nif (meta == null) {\n    // resource was deleted — abort or recreate\n    return;\n}","typeGuard":"boolean resourceAlive = resourceManager.findMeta(ns, name, type) != null;","tryCatchPattern":"try {\n    resourceManager.updateBizTagsCas(ns, meta, tags);\n} catch (NacosApiException e) {\n    if (e.getErrCode() == NacosException.SERVER_ERROR\n        && e.getMessage().contains(\"Meta cas failed\")) {\n        // resource deleted mid-update — check if intentional, reload or abort\n    }\n    throw e;\n}","preventionTips":["Prevent concurrent delete and update on the same resource — use application-level coordination.","Ensure reaper/cleanup jobs do not target resources with active in-flight mutations.","Monitor for META_LOST occurrences as a signal of delete/write races."],"tags":["ai-registry","server-error","cas","concurrency","race-condition"],"backgroundTag":null,"analyzedSha":"9b989acdf181d00898f2e8839257bb2b2a3cefe3","analyzedAt":"2026-08-14T07:17:31.569Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}