{"record":{"id":"299a1c8e08386cdd","repo":"apache/dolphinscheduler","slug":"create-access-token-error","errorCode":"CREATE_ACCESS_TOKEN_ERROR","errorMessage":"CREATE_ACCESS_TOKEN_ERROR","messagePattern":"CREATE_ACCESS_TOKEN_ERROR","errorType":"error_code","errorClass":"ServiceException","httpStatus":null,"severity":"error","filePath":"dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/AccessTokenServiceImpl.java","lineNumber":137,"sourceCode":"        // 3. generate access token if absent\n        if (StringUtils.isBlank(token)) {\n            token = EncryptionUtils.getMd5(userId + expireTime + System.currentTimeMillis());\n        }\n\n        // 4. persist to the database\n        AccessToken accessToken = new AccessToken();\n        accessToken.setUserId(userId);\n        accessToken.setExpireTime(DateUtils.stringToDate(expireTime));\n        accessToken.setToken(token);\n        accessToken.setCreateTime(new Date());\n        accessToken.setUpdateTime(new Date());\n\n        int insert = accessTokenDao.insert(accessToken);\n\n        if (insert > 0) {\n            return accessToken;\n        }\n        throw new ServiceException(Status.CREATE_ACCESS_TOKEN_ERROR);\n    }\n\n    /**\n     * generate token\n     *\n     * @param loginUser\n     * @param userId     token for user\n     * @param expireTime token expire time\n     * @return token string\n     */\n    @Override\n    public String generateToken(User loginUser, int userId, String expireTime) {\n        return EncryptionUtils.getMd5(userId + expireTime + System.currentTimeMillis());\n    }\n\n    /**\n     * delete access token\n     *","sourceCodeStart":119,"sourceCodeEnd":155,"githubUrl":"https://github.com/apache/dolphinscheduler/blob/02eac45a1b6676e639fcbfb4be2243de5771b05d/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/AccessTokenServiceImpl.java#L119-L155","documentation":"createToken inserts the generated AccessToken via accessTokenDao.insert and returns it only when insert > 0; otherwise it throws ServiceException(Status.CREATE_ACCESS_TOKEN_ERROR). This means the database insert affected zero rows, so no token was persisted.","triggerScenarios":"Calling createToken when the INSERT into the access token table affects 0 rows — e.g. a database constraint violation mapped to a no-op, a connection/transaction failure swallowed by the DAO layer, or the token row being concurrently deleted between validation and insert.","commonSituations":"Database connectivity problems or read-only replicas; primary-key/unique constraint conflicts on regenerated tokens; MyBatis/DAO misconfiguration; DB out of space or session killed mid-insert.","solutions":["Check DolphinScheduler API server logs and the database for the underlying insert failure (connection errors, constraint violations, disk full).","Retry the token creation once the database is reachable and healthy.","Verify the access_token table schema and constraints match the deployed DolphinScheduler version (run any pending upgrade SQL).","Ensure the DAO's datasource points at a writable primary database, not a read-only replica."],"exampleFix":"// before: insert result ignored/zero silently surfacing as generic failure\nint insert = accessTokenDao.insert(accessToken);\n\n// after: confirm DB health, then retry creation\ncurl -X POST .../access-tokens -d '{\"userId\":42,\"expireTime\":\"2026-01-01\"}'","handlingStrategy":"retry","validationCode":"// verify DB connectivity before token creation\ntry (Connection c = dataSource.getConnection()) {\n    if (!c.isValid(3)) throw new IllegalStateException(\"Database unavailable\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    accessTokenService.createToken(loginUser, userId, expireTime, token);\n} catch (ServiceException e) {\n    if (e.getCode() == Status.CREATE_ACCESS_TOKEN_ERROR) {\n        // inspect server logs / DB state, then retry after fixing persistence\n        retryWithBackoff(() -> accessTokenService.createToken(loginUser, userId, expireTime, token));\n    } else { throw e; }\n}","preventionTips":["Monitor database health (connections, disk space, replication lag).","Keep the access_token table schema aligned with your DolphinScheduler version via upgrade SQL.","Point datasources at a writable primary, never a read-only replica.","Add unique-constraint awareness if tokens can be generated concurrently."],"tags":["database","access-token","insert","persistence"],"backgroundTag":"database-write-failed","analyzedSha":"02eac45a1b6676e639fcbfb4be2243de5771b05d","analyzedAt":"2026-09-06T17:43:00.555Z","contentChangedAt":"2026-09-06T17:43:00.555Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}