From 3a9d7b1facf37484ffc7e027bb8908de5a378820 Mon Sep 17 00:00:00 2001 From: Jake Keuhlen Date: Thu, 18 Jun 2026 15:25:33 -0600 Subject: [PATCH] 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) --- .github/workflows/haskell.yml | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/.github/workflows/haskell.yml b/.github/workflows/haskell.yml index 5049a8d9c..20c685d4b 100644 --- a/.github/workflows/haskell.yml +++ b/.github/workflows/haskell.yml @@ -68,10 +68,6 @@ jobs: cabal-version: ${{ matrix.cabal }} - name: Check MySQL connection run: mysql -utest -ptest -h127.0.0.1 --port=33306 test -e "SELECT 1;" - - name: Start MongoDB - uses: supercharge/mongodb-github-action@1.8.0 - with: - mongodb-version: '5.0' - name: Start Redis uses: shogo82148/actions-setup-redis@v1 - run: sudo apt-get update && sudo apt-get install -y libpcre3-dev @@ -87,6 +83,30 @@ jobs: ${{ runner.os }}-${{ matrix.ghc }}-${{ hashFiles('cabal.project.freeze') }} ${{ runner.os }}-${{ matrix.ghc }}- - run: cabal v2-build all --disable-optimization $CONFIG + # Start MongoDB *after* the heavy build, immediately before the tests that + # need it. Unlike postgres/mysql (declared as health-gated `services`), + # MongoDB is started by an action step with no readiness gate, and the + # test harness connects once with no retry. Starting it before the ~10m + # build left a long window where the container could be resource-starved + # and become unreachable, producing flaky "Connection refused" failures + # in the persistent-mongoDB suite. + - name: Start MongoDB + uses: supercharge/mongodb-github-action@1.12.0 + with: + mongodb-version: '5.0' + - name: Wait for MongoDB to accept connections + run: | + for i in $(seq 1 30); do + if (exec 3<>/dev/tcp/127.0.0.1/27017) 2>/dev/null; then + exec 3>&- 3<&- + echo "MongoDB is accepting connections on 127.0.0.1:27017" + exit 0 + fi + echo "Waiting for MongoDB... ($i/30)" + sleep 2 + done + echo "MongoDB did not become reachable in time" >&2 + exit 1 - run: cabal v2-test all --disable-optimization $CONFIG --test-options "--fail-on-focus" - run: cabal v2-bench all --disable-optimization $CONFIG - run: cabal v2-sdist all