Skip to content

tokenExchangeProfiles: Promise.all causes race condition between delete and create #1238

@shahvicky

Description

@shahvicky

Checklist

  • I have looked into the README and have not found a suitable solution or answer.
  • I have looked into the documentation and have not found a suitable solution or answer.
  • I have searched the issues and have not found a suitable solution or answer.
  • I have upgraded to the latest version of this tool and the issue still persists.
  • I have searched the Auth0 Community forums and have not found a suitable solution or answer.
  • I agree to the terms within the Auth0 Code of Conduct.

Description

Hi team,

I added tokenExchangeProfiles with name, type, subject_token_type, and action.
This profile already exists in my tenant (previously created via Management API). I want to check the configuration into code.

The CLI detects it should delete the existing profile and create from config (delete:1, create:1), and the create fails with a 409 conflict:

2025-12-18T00:48:08.874Z - debug: Start processChanges for tokenExchangeProfiles [delete:1] [update:0], [create:1], [conflicts:0]
2025-12-18T00:48:08.875Z - warn: Detected the following tokenExchangeProfile should be deleted. Doing so may be destructive.
You can enable deletes by setting 'AUTH0_ALLOW_DELETE' to true in the config

{}      
2025-12-18T00:48:08.961Z - error: Problem running command import during stage processChanges when processing type tokenExchangeProfiles
2025-12-18T00:48:08.961Z - error: Problem creating tokenExchangeProfiles {}
ConflictError: ConflictError
Status code: 409
Body: {
  "statusCode": 409,
  "error": "Conflict",
  "message": "Token exchange profile with the same subject_token_type already exists"
}
2025-12-18T00:48:08.961Z - debug: Error: Problem creating tokenExchangeProfiles {}
ConflictError: ConflictError
Status code: 409
Body: {
  "statusCode": 409,
  "error": "Conflict",
  "message": "Token exchange profile with the same subject_token_type already exists"
}
    at /usr/local/lib/node_modules/auth0-deploy-cli/lib/tools/auth0/handlers/tokenExchangeProfiles.js:212:23
    at process.processTicksAndRejections (node:internal/process/task_queues:105:5)

Even with AUTH0_ALLOW_DELETE=true, the code uses Promise.all which doesn't guarantee execution order. The comment says "Process changes in order: delete, create, update" but Promise.all runs them concurrently, so create could still race ahead of delete.
See: https://github.com/auth0/auth0-deploy-cli/blob/master/src/tools/auth0/handlers/tokenExchangeProfiles.ts#L174-L194

Expectation

Existing token exchange profiles remain as it is, and new profiles to be created

Reproduction

  1. Create a custom token exchange profile using the Management API explained here
  2. Use the same subject_token_type and the action in the tenant.yaml file in the tokenExchangeProfiles configuration

Deploy CLI version

Latest

Node version

v22.11.0

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions