Skip to content

Commit 6e198bb

Browse files
Pierre-Luc GagnéCopilot
andcommitted
fix: use TCP health check and retry loop for MySQL readiness in CI
The previous health check used 'mysqladmin ping -h localhost' which connects via Unix socket inside the container. This reports healthy before MySQL's TCP listener is ready, causing 'Lost connection to MySQL server at reading initial communication packet' when the Initialize database step attempts a TCP connection. Changes: - Health check now uses --protocol=tcp (127.0.0.1) to verify TCP listener is up, not just the socket - Initialize database step adds a TCP retry loop (up to 20 attempts, 2s sleep) to handle any remaining race condition between health check and host-side port availability Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 8609d07 commit 6e198bb

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

.github/workflows/ci.yml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ jobs:
7676
-e MYSQL_DATABASE=ds_mysql_test \
7777
-e MYSQL_USER=ds_mysql_test_user \
7878
-e MYSQL_PASSWORD=ds_mysql_test_password \
79-
--health-cmd="mysqladmin ping -h localhost" \
79+
--health-cmd="mysqladmin ping -h 127.0.0.1 --protocol=tcp" \
8080
--health-interval=5s \
8181
--health-timeout=10s \
8282
--health-retries=10 \
@@ -103,6 +103,20 @@ jobs:
103103
- name: Initialize database
104104
run: |
105105
sudo apt-get install -y mysql-client
106+
echo "Waiting for TCP connection on port $DS_MYSQL_TEST_PORT..."
107+
for i in $(seq 1 20); do
108+
if mysql -h 127.0.0.1 -P "$DS_MYSQL_TEST_PORT" -u root -proot \
109+
--connect-timeout=5 -e "SELECT 1" > /dev/null 2>&1; then
110+
echo "TCP connection established"
111+
break
112+
fi
113+
if [ "$i" = "20" ]; then
114+
echo "MySQL TCP port did not become available in time"
115+
exit 1
116+
fi
117+
echo "Waiting for TCP... ($i/20)"
118+
sleep 2
119+
done
106120
mysql -h 127.0.0.1 -P "$DS_MYSQL_TEST_PORT" -u root -proot \
107121
< tests/integration/docker/init-db.sql
108122

0 commit comments

Comments
 (0)