Skip to content

Commit 3a9d7b1

Browse files
jkeuhlenclaude
andcommitted
ci: fix flaky MongoDB "Connection refused" failures
The persistent-mongoDB test suite intermittently fails with `Network.Socket.connect: ... does not exist (Connection refused)`. Unlike postgres and mysql, which are declared as health-gated `services` (the job blocks until they report healthy, and mysql has an extra explicit connection check), MongoDB is started by an action step with no readiness gate, and the test harness (MongoInit.runConn) connects once with no retry. It was also started *before* the ~10 minute `cabal v2-build all`, leaving a long window in which the mongod container could be resource-starved and become unreachable by the time the tests ran. - Move "Start MongoDB" to immediately before `cabal v2-test`, after the build. - Add a readiness gate that waits for the port to accept connections (a plain TCP check, mirroring the exact failure mode, with no mongo-client dependency). - Bump supercharge/mongodb-github-action 1.8.0 -> 1.12.0. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 855c20c commit 3a9d7b1

1 file changed

Lines changed: 24 additions & 4 deletions

File tree

.github/workflows/haskell.yml

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,6 @@ jobs:
6868
cabal-version: ${{ matrix.cabal }}
6969
- name: Check MySQL connection
7070
run: mysql -utest -ptest -h127.0.0.1 --port=33306 test -e "SELECT 1;"
71-
- name: Start MongoDB
72-
uses: supercharge/mongodb-github-action@1.8.0
73-
with:
74-
mongodb-version: '5.0'
7571
- name: Start Redis
7672
uses: shogo82148/actions-setup-redis@v1
7773
- run: sudo apt-get update && sudo apt-get install -y libpcre3-dev
@@ -87,6 +83,30 @@ jobs:
8783
${{ runner.os }}-${{ matrix.ghc }}-${{ hashFiles('cabal.project.freeze') }}
8884
${{ runner.os }}-${{ matrix.ghc }}-
8985
- run: cabal v2-build all --disable-optimization $CONFIG
86+
# Start MongoDB *after* the heavy build, immediately before the tests that
87+
# need it. Unlike postgres/mysql (declared as health-gated `services`),
88+
# MongoDB is started by an action step with no readiness gate, and the
89+
# test harness connects once with no retry. Starting it before the ~10m
90+
# build left a long window where the container could be resource-starved
91+
# and become unreachable, producing flaky "Connection refused" failures
92+
# in the persistent-mongoDB suite.
93+
- name: Start MongoDB
94+
uses: supercharge/mongodb-github-action@1.12.0
95+
with:
96+
mongodb-version: '5.0'
97+
- name: Wait for MongoDB to accept connections
98+
run: |
99+
for i in $(seq 1 30); do
100+
if (exec 3<>/dev/tcp/127.0.0.1/27017) 2>/dev/null; then
101+
exec 3>&- 3<&-
102+
echo "MongoDB is accepting connections on 127.0.0.1:27017"
103+
exit 0
104+
fi
105+
echo "Waiting for MongoDB... ($i/30)"
106+
sleep 2
107+
done
108+
echo "MongoDB did not become reachable in time" >&2
109+
exit 1
90110
- run: cabal v2-test all --disable-optimization $CONFIG --test-options "--fail-on-focus"
91111
- run: cabal v2-bench all --disable-optimization $CONFIG
92112
- run: cabal v2-sdist all

0 commit comments

Comments
 (0)