cypress: cy.visit() failed trying to load ESOCKETTIMEDOUT

Current behavior:

  CypressError: cy.visit() failed trying to load:
 We attempted to make an http request to this URL but the request failed without a response.
 We received this error at the network level:
   > Error: ESOCKETTIMEDOUT
 Common situations why this would fail:
     - you don't have internet access
     - you forgot to run / boot your web server
     - your web server isn't accessible
     - you have weird network configuration settings on your computer
 The stack trace for this error is:
 Error: ESOCKETTIMEDOUT
     at ClientRequest.<anonymous> (/root/.cache/Cypress/4.2.0/Cypress/resources/app/packages/server/node_modules/request/request.js:816:19)
     at Object.onceWrapper (events.js:299:28)
     at ClientRequest.emit (events.js:210:5)
     at TLSSocket.emitRequestTimeout (_http_client.js:690:9)
     at Object.onceWrapper (events.js:299:28)
     at TLSSocket.emit (events.js:210:5)
     at TLSSocket.Socket._onTimeout (net.js:468:8)
     at listOnTimeout (internal/timers.js:531:17)
     at processTimers (internal/timers.js:475:7)
 Because this error occurred during a 'before each' hook we are skipping the remaining tests in the current suite: 'Suite Tests'
image: 'cypress/base'

stages:
  - e2e

end-to-end testing:
  stage: e2e
  script:
    - npm install
    - npm test

Desired behavior:

Does not start testing on gitlab, but on local machine it does works

Test code to reproduce

Starts the tests in gitlab

Versions

Cypress: 4.2.0 Image: cypress/base

About this issue

  • Original URL
  • State: open
  • Created 4 years ago
  • Reactions: 25
  • Comments: 94 (8 by maintainers)

Commits related to this issue

Most upvoted comments

Adding this to the cy.visit() function solved it for me:

cy.visit(url, { headers: { "Accept-Encoding": "gzip, deflate" } });

… as referenced here: https://github.com/cypress-io/cypress/issues/943#issuecomment-730705557

We were able to solve this issue for our tests with our specific tech stack. We were using Next.js and our Cypress tests ran with the GitHub action.

We changed from:

with:
  start: yarn dev

to

with:
  build: npm run build
  start: npm start
  wait-on: 'http://localhost:3000'

Which caused our tests to run a lot faster and the GitHub action actually waits for the response of the server. We needed BOTH changes because the tests were running on the landing page (which loads fast even in dev mode) before the server was ready, which was fixed by the wait-on. And running the build helped to stay within the timeout window on the slower pages.

+1

getting the same issue via github

I am having the same issue… 😦 Is there no resolution after a year?

Hello everyone. Any updates on this issue, still opened since April 18? or any resolution process? Thanks

@nagash77, I have started experiencing this with Cypress 12.9.0. Although I understand that a reproducible example would make debugging this much easier, it is often not easy for the consumer of Cypress to produce one, however, it should be easier for the maintainers and developers to understand what is going on.

I had a similar problem running cypress against a website from a locally running docker container. For me, a call to cy.visit(…) inside a before()-hook failed if the server took longer than 30 seconds to respond. According to the documentation, pageLoadTimeout is responsible for cy.visit(…), but i fixed it using responseTimeout. Playing around with different values of these two timeouts i figured out that the ESOCKETTIMEDOUT occurs if the server does not respond in during responseTimeout although pageLoadTimeout was set high enough when using this in a before/beforeEach-hook.

@jennifer-shehane is this intended? https://docs.cypress.io/guides/references/configuration.html#Timeouts says otherwise.

I threw together a simple express server that waited before sending the response to test this, because cypress itself, the request package of cypress and chrome in headless mode all took about 45 sec to access the page, while normal chrome or curl are usually faster. The set timeout was the highest i could reach without it being rounded up to 30 and thus causing the error.

const express = require("express");
const app = express();
const port = 3000;
app.get("/", (req, res) => {
  res.setTimeout(
    29980, () => {
    res.send("ok");
    });
});

app.listen(port, () => {
  console.log(`Example app listening at http://localhost:${port}`);
});

Update, I remove these packages from the project and all tests return to pass:

    "@material-ui/core": "^4.11.0",
    "@material-ui/icons": "^4.9.1",

Hi, everyone, some news?

We had the same problem when adding a new test file, the first test file started failing only one test:

We use github-actions.

 1) Auth
       should redirect private page to /login:
     CypressError: `cy.visit()` failed trying to load:

http://localhost:3000/

We attempted to make an http request to this URL but the request failed without a response.

We received this error at the network level:

  > Error: ESOCKETTIMEDOUT

Common situations why this would fail:
  - you don't have internet access
  - you forgot to run / boot your web server
  - your web server isn't accessible
  - you have weird network configuration settings on your computer
      at http://localhost:3000/__cypress/runner/cypress_runner.js:157710:23
      at visitFailedByErr (http://localhost:3000/__cypress/runner/cypress_runner.js:157065:12)
      at http://localhost:3000/__cypress/runner/cypress_runner.js:157709:11
      at tryCatcher (http://localhost:3000/__cypress/runner/cypress_runner.js:10325:23)
      at Promise._settlePromiseFromHandler (http://localhost:3000/__cypress/runner/cypress_runner.js:8260:31)
      at Promise._settlePromise (http://localhost:3000/__cypress/runner/cypress_runner.js:8317:18)
      at Promise._settlePromise0 (http://localhost:3000/__cypress/runner/cypress_runner.js:8362:10)
      at Promise._settlePromises (http://localhost:3000/__cypress/runner/cypress_runner.js:8438:18)
      at _drainQueueStep (http://localhost:3000/__cypress/runner/cypress_runner.js:5032:12)
      at _drainQueue (http://localhost:3000/__cypress/runner/cypress_runner.js:5025:9)
      at Async.../../node_modules/bluebird/js/release/async.js.Async._drainQueues (http://localhost:3000/__cypress/runner/cypress_runner.js:5041:5)
      at Async.drainQueues (http://localhost:3000/__cypress/runner/cypress_runner.js:4911:14)
  From Your Spec Code:
      at Context.eval (http://localhost:3000/__cypress/tests?p=cypress/integration/auth.spec.ts:103:12)
  
  From Node.js Internals:
    Error: ESOCKETTIMEDOUT
        at ClientRequest.<anonymous> (/home/runner/.cache/Cypress/5.3.0/Cypress/resources/app/packages/server/node_modules/@cypress/request/request.js:816:19)
        at Object.onceWrapper (events.js:312:28)
        at ClientRequest.emit (events.js:223:5)
        at Socket.emitRequestTimeout (_http_client.js:690:9)
        at Object.onceWrapper (events.js:312:28)
        at Socket.emit (events.js:223:5)
        at Socket._onTimeout (net.js:474:8)
        at listOnTimeout (internal/timers.js:531:17)
        at processTimers (internal/timers.js:475:7)

We are experiencing the same issue as https://github.com/cypress-io/cypress/issues/5975. Localhost requests all throw ESOCKETTIMEDOUT error. The error happens every time.

image

I tried @rubiii and @hslee16 approaches but we still encounter the error.

Hello, Any update @jennifer-shehane ? Issue still open after 2 years now… we’re getting ESOCKETTIMEDOUT error with cypress 10.8.0 using Bitbucket Pipeline OR Jenkins running cypress/browsers image No error on local machine Thx

We are having this same issue in our ci/cd pipeline when cypress runs in it. does not happen locally. only in the GitLab pipeline. It is intermittent too : sometimes passes and some times it just fails.

@jennifer-shehane, @otalandim, @matzeeable - I’m seeing something similar. I’m unable to visit a certain URL (www.tesla.com) when tests are running in CircleCI (also tried BitBucket) - I receive the infamous ESOCKETTIMEDOUT error. It works fine if I run the tests via Test Runner or CLI (headless or headed). I tried increasing the pageLoadTimeout but that didn’t work. I also tried both Electron and Chrome with same results. I also did confirm that replacing cy.visit with cy.request yields 200 response.

I’m using Cypress 4.6.0

This is my basic config.yml (CircleCI):

version: 2.1
orbs:
  cypress: cypress-io/cypress@1.23.0
workflows:
  build:
    jobs:
      - cypress/run

And a simple test that will run fine in Test Runner/CLI, but fail on Circle CI/BitBucket:

  it.only('Test Tesla Link', () => {
    cy.visit('https://www.tesla.com', {
      headers: {
        "Accept-Encoding": "gzip, deflate, br"
      }
    })

Maybe, it will be helpful for somebody.

We faced the same issue a few days ago while using Github Action. In our case, it turned out that Cypress tests don’t actually wait until the server is started. The Angular app began to listen on port only in the middle of testing. Luckily, Cypress action has a solution for this:

      - name: "Run Tests"
        id: tests
        uses: cypress-io/github-action@v6
        with:
            build: npm run build
            start: npm run start
            wait-on: "http://localhost:4200" # URL to wait before tests
            wait-on-timeout: 300 # How long to wait in seconds
            browser: firefox

Getting same issue with latest Cypress 13.1.0 on CircleCI runs - locally no issues in headed and headless mode, any official comments on this from Cypress team?

I have tried all the solutions presente here, nothing works.

I’m facing the same issue running cypress 10.11.0 with Nx 14 and Nextjs 12.

My cypress.config.ts:

const cypressJsonConfig = {
  baseUrl: 'http://localhost:4002',
  fileServerFolder: '.',
  fixturesFolder: './src/fixtures',
  video: true,
  screenshot: true,
  chromeWebSecurity: false,
  env: {
    failSilently: false,
  },
  viewportWidth: 1440,
  viewportHeight: 900,
  requestTimeout: 120000,
  pageLoadTimeout: 120000,
  defaultCommandTimeout: 120000,
  specPattern: 'src/e2e/**/*.cy.{js,jsx,ts,tsx}',
  supportFile: 'src/support/e2e.ts',
}

My Github action:

name: Cypress Tests

on:
  pull_request:
    types: [opened, synchronize, reopened, ready_for_review]
    branches:
      - develop

jobs:
  cypress-run:
    name: Cypress test
    runs-on: ubuntu-20.04
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-node@v3
        with:
          node-version-file: '.nvmrc'
      - name: Cache central NPM modules
        uses: actions/cache@v3
        with:
          path: ~/.npm
          key: ${{ runner.os }}-node-${{ github.ref }}-${{ hashFiles('**/package-lock.json') }}
          restore-keys: |
            ${{ runner.os }}-node-${{ github.ref }}-${{ hashFiles('**/package-lock.json') }}
      - name: Cache Cypress binary
        uses: actions/cache@v3
        with:
          path: ~/.cache/Cypress
          key: cypress-${{ runner.os }}-cypress-${{ github.ref }}-${{ hashFiles('**/package.json') }}
          restore-keys: |
            cypress-${{ runner.os }}-cypress-${{ github.ref }}-${{ hashFiles('**/package.json') }}
      - name: Cache local node_modules
        uses: actions/cache@v3
        with:
          path: node_modules
          key: ${{ runner.os }}-node-modules-${{ github.ref }}-${{ hashFiles('**/package-lock.json') }}
          restore-keys: |
            ${{ runner.os }}-node-modules-${{ github.ref }}-
      - name: Clean install
        run: npm ci

      - name: Cypress tests
        run: npx nx e2e web-app-e2e:e2e --record
        env:
          CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
          TERM: xterm
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          YACOOBA_ENV: develop
          NEXT_PUBLIC_API_URL: https://our-dev-url-api

Error message:

cy.visit() failed trying to load:

http://localhost:4002/events/jazz-concert-c01894a6

We attempted to make an http request to this URL but the request failed without a response.

We received this error at the network level:

  > Error: ESOCKETTIMEDOUT

Common situations why this would fail:

you don't have internet access
you forgot to run / boot your web server
your web server isn't accessible
you have weird network configuration settings on your computer
Because this error occurred during a before each hook we are skipping the remaining tests in the current suite: Event Page

image

wait-on: 'http://localhost:3000'

“wait-on: ‘http://localhost:3000’” worked for me. Thanks a lot!

@theoshallburn Thanks for the repro and the lead on the responseTimeout.

Increasing the responseTimeout doesn’t fix the original issue with the Tesla and BestBuy website - there’s something preventing that website from loading altogether in Cypress so it eventually timesout.

Reproducible example

  1. Run node app.js
  2. In new terminal run cypress open

package.json

{
  "devDependencies": {
    "cypress": "6.2.0",
    "express": "4.17.1"
  }
}

app.js

const express = require('express')
const app = express()

app.get('/', (req, res) => {
  res.setTimeout(
    // setting this < 30000 will pass
    // setting this to 30000 will throw ESOCKETTIMEDOUT
    30000, () => {
      res.send('ok')
    })
})

app.listen(port, () => {
  console.log(`Example app listening at http://localhost:3000`)
})

cypress/integration/spec.js

it('visit', () => {
  // this `pageLoadTimeout` does not prevent ESOCKETTIMEDOUT
  // cy.visit('http://localhost:3000', { pageLoadTimeout: 80000 })
  
  // this `responseTimeout` does prevent ESOCKETTIMEDOUT
  cy.visit('http://localhost:3000', { responseTimeout: 31000 })

  cy.contains('ok')
})

30000 setTimeout without responseTimeout increase

Screen Shot 2020-12-30 at 5 51 06 PM

30000 setTimeout with responseTimeout: 31000

Screen Shot 2020-12-30 at 5 59 46 PM

Workaround

If your app takes > 30 seconds to load and does eventually load, increase the responseTimeout passed to cy.visit(). I’ll have to check and see why this is.

We were close to cancel our move to Cypress, because at some point while adding more and more tests, we experienced more and more failing tests. Interestingly it were always the last few tests that were failing, regardless of which tests ran last.

We are running Cypress in a Docker container on GitLab and we finally solved this problem for us by splitting the docker-compose startup and actually running the tests into separate commands. Here’s the change to our gitlab-ci.yml:

Before:

acceptance_tests:
  script:
    - docker-compose run --use-aliases acceptance-tests /opt/project/bin/run-tests

After:

acceptance_tests:
  script:
    - docker-compose up -d nginx rails-app frontend postgres && docker-compose run --use-aliases acceptance-tests /opt/project/bin/run-tests

🤷

@jennifer-shehane we also been running into this for a while. Any update on this? How can we help? Repro’s are a bit hard to deliver for our project, but since so many people seem to run into this shouldn’t be that hard for someone to create a repro. For what it’s worth: we’re using Cloud (parallelism) and have been experiencing this issue for quite some time. Haven’t been able to find any logic in why or when it happens. Seems somewhat random.

In case it helps anyone else: I ran into this at work because a cypress test job was running against a frontend served by webpack-dev-server. The dev server will hold requests open until it finishes bundling so as our client builds got longer we started hitting the cypress responseTimeout. Bumped responseTimeout for now though a better fix would be for the job not to start running cypress until the client finishes bundling

@sosnet You can put this in your cypress support file:

before(() => {
  cy.intercept("*", (req) => {
    req.headers["Accept-Encoding"] = "gzip, deflate";
  });
});

Thanks Adding this to the cy.visit() function solved it for me too

cy.visit(url, { headers: { “Accept-Encoding”: “gzip, deflate” } });

… as referenced here: #943 (comment)

Take a look at the start-server-and-test NPM module

Sent from my iPhone

On Jun 13, 2021, at 10:21, Kolotushkin Maxim @.***> wrote:

Faced the issue with BitBucker pipeline. The problem seems to be in dev server. It haven’t been started yet, but Cypress tried to visit it. For me worked

before(() => { cy.wait(20000); }); Of course the solution is not very good, but I haven’t found better one.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or unsubscribe.

Hi team, just want to report the issue here too. Using github cypress action.

Error message

Error: ESOCKETTIMEDOUT

Because this error occurred during a `before all` hook we are skipping the remaining tests in the current suite: `Staff profile page `
     at http://0.0.0.0:5051/__cypress/runner/cypress_runner.js:157807:23
     at visitFailedByErr (http://0.0.0.0:5051/__cypress/runner/cypress_runner.js:157162:12)
     at http://0.0.0.0:5051/__cypress/runner/cypress_runner.js:157806:11
     at tryCatcher (http://0.0.0.0:5051/__cypress/runner/cypress_runner.js:10325:23)
     at Promise._settlePromiseFromHandler (http://0.0.0.0:5051/__cypress/runner/cypress_runner.js:8260:31)
     at Promise._settlePromise (http://0.0.0.0:5051/__cypress/runner/cypress_runner.js:8317:18)
     at Promise._settlePromise0 (http://0.0.0.0:5051/__cypress/runner/cypress_runner.js:8362:10)
     at Promise._settlePromises (http://0.0.0.0:5051/__cypress/runner/cypress_runner.js:8438:18)
     at _drainQueueStep (http://0.0.0.0:5051/__cypress/runner/cypress_runner.js:5032:12)
     at _drainQueue (http://0.0.0.0:5051/__cypress/runner/cypress_runner.js:5025:9)
     at Async.../../node_modules/bluebird/js/release/async.js.Async._drainQueues (http://0.0.0.0:5051/__cypress/runner/cypress_runner.js:5041:5)
     at Async.drainQueues (http://0.0.0.0:5051/__cypress/runner/cypress_runner.js:4911:14)
 From Your Spec Code:
     at Context.eval (http://0.0.0.0:5051/__cypress/tests?p=packages/staff/integration-test/integration/examples/staffProfile/edgeCases/supportReachLimit.spec.ts:16956:16)

Test file

No complicated request

  cy.loadData(staffProfileMockApi).then(() => {
      cy.visit('http://0.0.0.0:5051/')
    })

action.yml

  - name: Cypress test
        uses: cypress.io/github-action@v2
        with:
          start: yarn start:server
          wait-on: 'http://0.0.0.0:5051'

I have tried: 1. downgrade cypress to 5.1 2.make requestTimeout to 30s 3. Add header in request. But no luck. All tests pass in local env.

Also some previous investigation into bestbuy.com and staples.com issuing an ESOCKETTIMEDOUT - #2778 (comment)

There was a comment in the request library mentioning why this ESOCKETTIMEDOUT may be happening with the request library. request/request#2738 (comment)

I think bestbuy.com may be blocking the request due to the default headers being sent from request. If the request is made with the same headers that the axios request is sending, it does not time out:

const request = require('request');
const axios = require('axios');
const url = 'http://www.bestbuy.com/';
request({
  url: url,
  timeout: 5000,
  headers: {
    "Accept": "application/json, text/plain, */*",
    "User-Agent": "axios/0.18.0"
  }
}, (error, response, body) => {
  if (!error)
    console.log(`request got ${response.statusCode}`);
  else
    console.error(`request got an error`, error);
});

axios.get(url).then((ret) => {
  console.log(`Axios got ${ret.status}`);
});

The above clued me in on how to solve this.

    cy.visit({
      url: 'www.bestbuy.com',
      headers: {
        "Accept": "application/json, text/plain, */*",
        "User-Agent": "axios/0.18.0"
      }
    });

Hopefully this is helpful to someone.

Hi @jennifer-shehane and @otalandim,

I had the same issue, locally all is working fine but on GitLab CI, one or two tests always fail with the above mentioned error message: Error: ESOCKETTIMEDOUT.

Currently, I workaround this by using cypress-plugin-retries, so when the error happens, the test gets retried.

Unfortunately I can’t tell you how to reprocedure the whole thing, because it very sporadically always hits different tests. But basically it happens at cy.visit(). Previously I used cypress@3.8.4 and never got this error before. I read more about it in GitHub issues and perhaps this is another “workaround”: https://github.com/cypress-io/cypress/issues/350#issuecomment-267704772; but I did not test it.

Similar tickets: #6547, #5975 Used Cypress Version: 4.4.1

@jennifer-shehane Hello, my company has been having issues with the performance of cy.visit() and cy.request() timing out when running cypress integration tests on our Vercel preview deploymens in GithubActions. I have implemented timeout props to the options object on both cy methods, as well as the headers “Accept-Encoding” suggestion, but am still sometimes receiving the ESOCKETTIMEDOUT message. I am running Cypress 9.x and am not having this problem when running Cypress on my local machine. We only receive this ESOCKETTIMEDOUT when run through GithubActions. Do you have any other suggestions for a fix for this?

@euclidesdry @vjvibhanshu which cypress version are you using?

Adding this to the cy.visit() function solved it for me:

cy.visit(url, { headers: { "Accept-Encoding": "gzip, deflate" } });

… as referenced here: #943 (comment)

It resolved for me too!

Hello, I have regularly experienced this issue with my Production host.

for the Stage - all works as expected and tests successfully passed. When I’m running tests from a local machine - the same - all fine.

but when the tests are executed with GitLab CI on the Production host - 50% time it just fails with unable to open the requested URL. Screenshot 2021-09-20 at 12 36 31

Surprisingly, removing both optimization and buildOptimizer from angular.json seems to have ESOCKETTIMEDOUT error solved in my GitLab CI. Btw, I am serving Angular app in CI environment.

Yeah, the issue is probably related to tree-shaking. Glad it helped!

If you’re running the Angular dev-server with Cypress, removing optimization and buildOptimizer from your build options in angular.json might help.

Any update on this one @jennifer-shehane. I am getting the same when using Travis CI. I implemented Contrast (security and vulnerabilities agent). Runs local, times-out in Travis regardless of all the attempts to the contrary following all the issues here. Thanks.

I see that you are using an older version of Cypress. Please update to the current version of Cypress and let us know if this is still happening for you. Your issue may have already been fixed. Thanks!