apache/dolphinscheduler · error · ServiceException

CREATE_ACCESS_TOKEN_ERROR

CREATE_ACCESS_TOKEN_ERROR

Error message

CREATE_ACCESS_TOKEN_ERROR

What it means

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.

Source

Thrown at dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/AccessTokenServiceImpl.java:137

        // 3. generate access token if absent
        if (StringUtils.isBlank(token)) {
            token = EncryptionUtils.getMd5(userId + expireTime + System.currentTimeMillis());
        }

        // 4. persist to the database
        AccessToken accessToken = new AccessToken();
        accessToken.setUserId(userId);
        accessToken.setExpireTime(DateUtils.stringToDate(expireTime));
        accessToken.setToken(token);
        accessToken.setCreateTime(new Date());
        accessToken.setUpdateTime(new Date());

        int insert = accessTokenDao.insert(accessToken);

        if (insert > 0) {
            return accessToken;
        }
        throw new ServiceException(Status.CREATE_ACCESS_TOKEN_ERROR);
    }

    /**
     * generate token
     *
     * @param loginUser
     * @param userId     token for user
     * @param expireTime token expire time
     * @return token string
     */
    @Override
    public String generateToken(User loginUser, int userId, String expireTime) {
        return EncryptionUtils.getMd5(userId + expireTime + System.currentTimeMillis());
    }

    /**
     * delete access token
     *

View on GitHub (pinned to 02eac45a1b)

Solutions

  1. Check DolphinScheduler API server logs and the database for the underlying insert failure (connection errors, constraint violations, disk full).
  2. Retry the token creation once the database is reachable and healthy.
  3. Verify the access_token table schema and constraints match the deployed DolphinScheduler version (run any pending upgrade SQL).
  4. Ensure the DAO's datasource points at a writable primary database, not a read-only replica.

Example fix

// before: insert result ignored/zero silently surfacing as generic failure
int insert = accessTokenDao.insert(accessToken);

// after: confirm DB health, then retry creation
curl -X POST .../access-tokens -d '{"userId":42,"expireTime":"2026-01-01"}'
Defensive patterns

Strategy: retry

Validate before calling

// verify DB connectivity before token creation
try (Connection c = dataSource.getConnection()) {
    if (!c.isValid(3)) throw new IllegalStateException("Database unavailable");
}

Try / catch

try {
    accessTokenService.createToken(loginUser, userId, expireTime, token);
} catch (ServiceException e) {
    if (e.getCode() == Status.CREATE_ACCESS_TOKEN_ERROR) {
        // inspect server logs / DB state, then retry after fixing persistence
        retryWithBackoff(() -> accessTokenService.createToken(loginUser, userId, expireTime, token));
    } else { throw e; }
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of apache/dolphinscheduler@02eac45a1b (2026-09-06). Data as JSON: /api/errors/299a1c8e08386cdd. Report an issue: GitHub.