RDS MySQL instance intermittently stuck in error state on create (container readiness race)
#51
Ranotronarison
started this conversation in
Bugs
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
RDS MySQL instance intermittently stuck in
errorstate on create (container readiness race)Issue Description
Creating an
aws_db_instancewithengine = "mysql"via Terraform intermittently fails: the underlying LocalStack-managed MySQL sibling container is started successfully and becomes healthy, but LocalStack's own readiness probe gives up too early and marks the DB instanceerrorbefore the container is actually accepting connections. The instance never recovers from this state afterwards (DescribeDBInstanceskeeps reportingerrorindefinitely), even though the MySQL container itself is confirmed running and reachable minutes later. All other resources in the sameterraform apply(VPC, subnets, ALB, ACM, Route53, S3) create successfully every time — only the RDS MySQL engine is affected.Environment Information
localstack/localstack:2026.08.1(Pro, via Docker Compose)lstkCLI:0.23.0v1.16.1,hashicorp/awsprovider5.100.025.0.3Linux 6.6.87.2-microsoft-standard-WSL2(x86_64)docker-compose.yml:PERSISTENCE=1, volume-mounted/var/run/docker.sock(sibling-container mode)aws_db_instance):engine = "mysql",engine_versionunpinned tag resolving tomysql:8.4,db_subnet_group_namepointing at 2 private subnets,manage_master_user_password = true,skip_final_snapshot = trueReproduction Steps
docker compose up -d(LocalStack starts healthy)lstk terraform init -backend-config=backend.hcllstk terraform apply tfplan— plan includesmodule.rds[0].aws_db_instance.this(MySQL engine) alongside VPC/ALB/ACM/Route53/S3 resourcesmodule.rds[0].aws_db_instance.thispolls "Still creating..." for 100-110s, then fails:lstk aws rds describe-db-instancesconfirmsDBInstanceStatus: error, and stayserroron repeated checks minutes later — no self-recovery.docker psshows the sibling MySQL container (ls-mysql-<hash>, imagemysql:8.4) in stateUpand has been running fine the whole time, both on this attempt and a prior one on the same day with a different generated instance identifier — i.e. this has reproduced twice in the same session with two different instance IDs.Troubleshooting Attempts
mysql:8.4was already pulled/cached locally (5+ weeks old) before this run, ruling out a slow image-pull as the cause.docker psthat the sibling container the failed instance was backed by is stillUpand running well past the point LocalStack reportederror— the container itself never crashed or exited.applya second time (freshrandom_stringsuffix, brand-newaws_db_instance/new sibling container) — reproduced with a different, more specific error the second time (see logs below):mysqladminconnect refused onlocalhost:3306.terraform.tf,backend.hcl, and the provider lock file are correctly resolved, and every non-RDS resource in the same plan creates without issue.error, does not transition on its own even after the container is demonstrably ready — there appears to be no retry/re-check after the initial readiness window is exhausted.Root Cause Analysis
LocalStack's MySQL RDS engine emulation launches a sibling Docker container (per the RDS docs: "A MySQL server will be launched in a new Docker container upon requesting the MySQL engine") and then polls it with
mysqladmin ping/execcalls to decide when the instance becomesavailable. This appears to be a fixed-budget polling loop (roughly ~100-110s observed across two runs) rather than one tied to actualmysqldreadiness. When the container takes longer than that budget to finish MySQL's first-run initialization (data directory setup + entrypoint script) and start accepting TCP connections on3306, the probe'smysqladmin/execcall fails once, and LocalStack immediately marks the instanceerrorand never retries — even though the container goes on to become fully healthy seconds/minutes later. BecauseDescribeDBInstances.DBInstanceStatusisn't an attribute Terraform'saws_db_instanceresource tracks for drift, a plain re-applywon't detect or fix the stuck instance either; it has to be deleted and recreated out of band.The two failures observed differ slightly in their surfaced error, which points at two edges of the same race rather than two separate bugs:
ContainerStateError: Container not yet started.— the readiness check ran before the container object itself was even in a "started" state.mysqladmin: connect to server at 'localhost' failed ... Can't connect to MySQL server on 'localhost:3306' (111)— the container was started, butmysqldwasn't accepting connections yet when the last poll attempt ran.Detailed Logs
Terraform apply output (2nd reproduction):
LocalStack container logs, 1st reproduction:
LocalStack container logs, 2nd reproduction (~2h later, same day, different instance id):
docker ps— both sibling containers running fine after LocalStack had already given up on them:lstk aws rds describe-db-instances— status never self-heals:All reactions