Portainer Edge Agent stack deploy idempotency during network partition retries
0 reputation · 20 Aug 2024, 15:37 UTC
0 reputation · 20 Aug 2024, 15:37 UTC
Portainer Edge Agents maintain a persistent WebSocket connection to the Portainer Server with exponential backoff retries (default 5s, configurable via EDGE_AGENT_RETRY_INTERVAL). When the Server dispatches a stack deployment and the acknowledgment is lost due to a network partition, the Server re-sends the command on reconnect.
The Edge Agent does not implement idempotency keys for stack deployments. If the first deployment attempt partially succeeded (e.g., images pulled, some containers created) before the partition, the retry will re-execute the same deployment, potentially creating duplicate resources such as named volumes with fixed names or causing container name conflicts.
The Edge Agent uses exponential backoff (default 5s, configurable via EDGE_AGENT_RETRY_INTERVAL) to reconnect. When the Server sends a stack deployment and the acknowledgment is lost, the Server re-queues the deployment on reconnect. The Agent has no built-in idempotency key or pre-deploy hook mechanism.
stackname-$(uuidgen | cut -c1-8)) and checks for existing resources before applying.The Server does not currently expose per-error-class retry suppression. All non-200 responses trigger retries. As a workaround, you can:
EDGE_AGENT_RETRY_INTERVAL to a higher value to reduce retry frequency.Implement an automated pipeline step that:
now - 5m).Ensure the cleanup script itself is idempotent to avoid accidental deletion of valid resources.
To confirm behavior in your environment:
Retrying stack deployment entries with identical stack names after a network interruption.Use comments to ask for clarification. Post a solution as an answer.
35,775 reputation · 20 Aug 2024, 22:16 UTC
While the Portainer Server applies a Portainer-Stack-Deployment-ID label to resources, the Edge Agent, in its current retry logic, does not consume this ID to check for prior state before re-executing deployment commands like docker stack deploy.
my_data) will cause conflicts regardless of the deployment ID.8080:80) are inherently non-idempotent at the Swarm/Docker level during concurrent retries.For practical verification, ensure the Edge Agent is at least version 2.19 to confirm label presence in payloads.