-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Description
Summary
When creating multiple domains for the same application concurrently using the Dokploy API (via Promise.all with multiple domainCreate calls), only one of the domains gets added to the Traefik configuration. This appears to be a race condition in how Dokploy updates the Traefik config when processing concurrent domain creation requests.
Environment
- Dokploy API endpoint:
https://app.dokploy.com/api - API authentication: Using API key via
x-api-keyheader - Application type: Docker application
Steps to Reproduce
- Create a Dokploy application using the API
- Attempt to create multiple domains for the same application concurrently:
await Promise.all([
domainCreate({
baseUrl: "https://app.dokploy.com/api",
headers: { "x-api-key": process.env.DOKPLOY_API_KEY },
body: {
applicationId,
host: \`one-\${id}.example.com\`,
port: 3000,
https: true,
domainType: "application",
certificateType: "letsencrypt",
},
throwOnError: true,
}),
domainCreate({
baseUrl: "https://app.dokploy.com/api",
headers: { "x-api-key": process.env.DOKPLOY_API_KEY },
body: {
applicationId,
host: \`two-\${id}.example.com\`,
port: 3001,
https: true,
domainType: "application",
certificateType: "letsencrypt",
},
throwOnError: true,
}),
]);Expected Behavior
Both domains should be created and added to the Traefik configuration, with both domains being accessible and properly routed.
Actual Behavior
Only one of the domains (seemingly random which one) gets added to the Traefik configuration. The other domain appears to be created in the database but is not reflected in the Traefik config.
Workaround
Calling the `domainCreate` API endpoints sequentially instead of concurrently resolves the issue:
await domainCreate({
baseUrl: "https://app.dokploy.com/api",
headers: { "x-api-key": process.env.DOKPLOY_API_KEY },
body: {
applicationId,
host: \`one-\${id}.example.com\`,
port: 3000,
https: true,
domainType: "application",
certificateType: "letsencrypt",
},
throwOnError: true,
});
await domainCreate({
baseUrl: "https://app.dokploy.com/api",
headers: { "x-api-key": process.env.DOKPLOY_API_KEY },
body: {
applicationId,
host: \`two-\${id}.example.com\`,
port: 3001,
https: true,
domainType: "application",
certificateType: "letsencrypt",
},
throwOnError: true,
});Root Cause Analysis
This appears to be a race condition where concurrent domain creation requests for the same application conflict when updating the Traefik configuration file. Possible causes:
- Lack of locking mechanism when updating Traefik config
- Missing transaction isolation when processing concurrent domain creation requests
- Race condition in the Traefik config regeneration process
Impact
- API consumers must implement sequential domain creation, increasing latency
- Potential data inconsistency between database state and Traefik configuration
- Unexpected behavior when using the API programmatically
Suggested Fix
Implement proper synchronization/locking when updating the Traefik configuration, or ensure that domain creation operations for the same application are queued and processed sequentially at the API level.