{"record":{"id":"1964498c26f59a6a","repo":"apache/rocketmq","slug":"the-user-is-existed","errorCode":null,"errorMessage":"The user is existed","messagePattern":"The user is existed","errorType":"exception","errorClass":"AuthenticationException","httpStatus":null,"severity":"error","filePath":"auth/src/main/java/org/apache/rocketmq/auth/authentication/manager/AuthenticationMetadataManagerImpl.java","lineNumber":105,"sourceCode":"                throw new AuthenticationException(\"Init inner client authentication credentials error\", e);\n            }\n        }\n    }\n\n    @Override\n    public CompletableFuture<Void> createUser(User user) {\n        CompletableFuture<Void> result = new CompletableFuture<>();\n        try {\n            this.validate(user, true);\n            if (user.getUserType() == null) {\n                user.setUserType(UserType.NORMAL);\n            }\n            if (user.getUserStatus() == null) {\n                user.setUserStatus(UserStatus.ENABLE);\n            }\n            result = this.getAuthenticationMetadataProvider().getUser(user.getUsername()).thenCompose(old -> {\n                if (old != null) {\n                    throw new AuthenticationException(\"The user is existed\");\n                }\n                return this.getAuthenticationMetadataProvider().createUser(user);\n            });\n        } catch (Exception e) {\n            this.handleException(e, result);\n        }\n        return result;\n    }\n\n    @Override\n    public CompletableFuture<Void> updateUser(User user) {\n        CompletableFuture<Void> result = new CompletableFuture<>();\n        try {\n            this.validate(user, false);\n            result = this.getAuthenticationMetadataProvider().getUser(user.getUsername()).thenCompose(old -> {\n                if (old == null) {\n                    throw new AuthenticationException(\"The user is not exist\");\n                }","sourceCodeStart":87,"sourceCodeEnd":123,"githubUrl":"https://github.com/apache/rocketmq/blob/293f5885719fc4aa3619446a1900f58ccfcfdd29/auth/src/main/java/org/apache/rocketmq/auth/authentication/manager/AuthenticationMetadataManagerImpl.java#L87-L123","documentation":"Admin operation createUser was rejected because getUser(username) returned an existing record. Usernames are unique in the auth metadata, and creation is a check-then-create sequence inside the manager, so duplicates fail with this error.","triggerScenarios":"Calling the createUser RPC / mqadmin createUser for a username that already exists in the metadata provider's store, including a soft-deleted or default account still present.","commonSituations":"Re-running a provisioning script that is not idempotent; creating the default super user after initialization already created it; retrying a partially succeeded creation.","solutions":["If the intent is to change the user, call updateUser instead of createUser.","Delete the existing user first (deleteUser) if it is truly stale, then re-create.","Make provisioning scripts check getUser() before createUser (or treat this error as success for idempotent bootstrapping)."],"exampleFix":"// before\nauthManager.createUser(User.of(\"alice\", \"pw\").toBuilder().userType(UserType.SUPER).build()); // throws if exists\n\n// after\nauthManager.getUser(\"alice\")\n    .thenCompose(existing -> existing != null\n        ? authManager.updateUser(User.of(\"alice\", \"newPw\").toBuilder().userType(UserType.SUPER).build())\n        : authManager.createUser(User.of(\"alice\", \"pw\").toBuilder().userType(UserType.SUPER).build()));","handlingStrategy":"try-catch","validationCode":"// Idempotent provisioning: check before create\nauthManager.getUser(user.getUsername())\n    .thenCompose(existing -> existing != null\n        ? CompletableFuture.completedFuture(null)\n        : authManager.createUser(user));","typeGuard":null,"tryCatchPattern":"catch (AuthenticationException e) { if message contains \"user is existed\" -> treat create as already-done (idempotent success) or switch to updateUser; never crash the provisioning script. }","preventionTips":["Make bootstrap scripts idempotent with get-then-create","Treat 'already exists' as a benign outcome in provisioning pipelines"],"tags":["rocketmq","user-management","create","duplicate"],"backgroundTag":null,"analyzedSha":"293f5885719fc4aa3619446a1900f58ccfcfdd29","analyzedAt":"2026-08-14T11:50:13.822Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}