Cypress E2E tests fail with ESOCKETTIMEDOUT and request timeouts when calling localhost in CircleCI

Hi all.

Problem

Our Cypress E2E tests intermittently fail in CircleCI with ESOCKETTIMEDOUT and “timed out waiting 30000ms” when calling our Flask app on localhost. Sometimes runs pass, sometimes they fail.

Typical pattern: tests on port 5000 pass, then requests to 5011 (and sometimes 5003) start timing out. We use nc -z in our startup script to wait until each port is listening before tests run, but Cypress still times out when it hits those ports.

Environment

  • CircleCI

  • Cypress: 14.5.4

  • All services run in the same job (Datastore emulator, task queue emulator, gunicorn x3)

Setup

  • Flask Service 1: gunicorn on port 5000

  • Flask Service 2: gunicorn on port 5003

  • Flask Service 3: gunicorn on port 5011

  • Datastore emulator on 8248, task queue emulator on 9090

  • Services are started in the background with &; our script to start the server waits up to 90s for each port with nc -z before continuing

Example errors

  • cy.request() to localhost:5011/… → ESOCKETTIMEDOUT

  • cy.request() to localhost:5003/… → “timed out waiting 30000ms”

  • cy.visit(‘/logout’) to localhost:5000 → ESOCKETTIMEDOUT

What we’ve tried

  • Port checks with nc -z before tests

    • With this we have confirmed the ports are all running before the tests start running on them
  • Extra waits and health checks before running tests

Question

  1. Why would this happen?
  2. Why do tests pass for a while and then start failing even though our port checks pass?
  3. Why would cy.request() and cy.visit() to localhost sometimes work and sometimes time out in CircleCI?

I can share our script we use the start the server with, CircleCI config YAML or anything else that would help.

Thanks,
Keeth