Cypress: CypressError: cy.visit() failed trying to load ESOCKETTIMEDOUT when run in CI

Created on 18 Apr 2020  路  21Comments  路  Source: cypress-io/cypress

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

circle gitlab blocking needs investigating bug

All 21 comments

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!

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 [email protected] 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, @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/[email protected]
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"
      }
    })

I'm having the same issue using CircleCI and that orb version: cypress-io/[email protected]

I'm using Chrome for the browser.

I can recreate this using our circleci orb with the test code below.

  • This does not fail during cypress open or cypress run locally.
  • This fails in Electron 80 and Chrome latest.

My failing PR here: https://github.com/cypress-io/circleci-orb-example/pull/11
Run with DEBUG logs: https://circleci.com/gh/cypress-io/circleci-orb-example/27

spec.js

it('Test Tesla Link', () => {
  cy.visit('https://www.tesla.com')
})

circle.yml

version: 2.1
orbs:
  cypress: cypress-io/cypress@1
workflows:
  build:
    jobs:
      - cypress/run:
          name: Debug with Cypress logs
          debug: 'cypress:*'

This issue seems to happen even inside of a Node.js REPL:

const rp = require('request-promise')

console.time('loading')

rp('https://www.tesla.com', { timeout: 15000 })
.then(() => console.timeEnd('loading'))
.catch((err) => console.error(err))

This will fail after 15s with ESOCKETTIMEDOUT (tested in Node 12.8.1).

My first idea was that www.tesla.com never finishes sending /, that it continually streams data... but that does not appear to be the case, loading the site in a regular web browser, the request ends once the content is served. So I'm not sure what the root cause is of this problem. But if the ESOCKETTIMEDOUT can be fixed in Node, that should fix it in Cypress as well.

Also some previous investigation into bestbuy.com and staples.com issuing an ESOCKETTIMEDOUT - https://github.com/cypress-io/cypress/issues/2778#issuecomment-516010247

There was a comment in the request library mentioning why this ESOCKETTIMEDOUT may be happening with the request library. https://github.com/request/request/issues/2738#issuecomment-369324868

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}`);
});

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.

We're seeing the exact same problem after adding more tests to our test suite and they're only failing when running via headless chrome on GitLab. We haven't found the root cause or a solution yet.
Cypress: 4.12.1 / Image: cypress/browsers:node12.16.2-chrome81-ff75

If we could figure out why Node.js can't load these websites, we could fix the issue. It's not exactly a Cypress issue, it seems to be reproducible with just regular Node HTTP requests: https://github.com/cypress-io/cypress/issues/7062#issuecomment-664776610

I can not reproduce the failure using the given example. Also Cypress forked the request library at @cypress/request, so even if the problem originated in the request library, it's certainly present in the fork as well.

Update (08/13): We were able to reproduce the problem using only @cypress/request. The problem only happens in our Docker/GitLab-Setup and it also happens with axios. After ~700 requests, we seem to run into some kind of limit. We're still investigating.

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.

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.

Same problem here!

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

馃し

+1

getting the same issue via github

reverting to use cypress version 5.1.0 fixes the issue for me

i installed cypress in laravel with the following guide https://github.com/laracasts/cypress after running the command php artisan cypress:boilerplate cypress no longer works @jennifer-shehane

any test application always gives me the following error:

TEST BODY
1
visit
/
CypressError
cy.visit() failed trying to load:

http://my-app.test/

The response we received from your web server was:

  > 500: Server Error

This was considered a failure because the status code was not 2xx.

If you do not want status codes to cause failures pass the option: failOnStatusCode: false
cypress/integration/ex_spec.js:2:5
  1 | it('works',() =>{
> 2 |   cy.visit('/').contains('Enviroment:Acceptance');
    |      ^
  3 | })

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.

For me, the problem was how I started the webserver. I'm using start-server-and-test and had to change start-server http://localhost:8080 to start-server http-get://localhost:8080 (see Note for webpack-dev-server users).

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)

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",
Was this page helpful?
0 / 5 - 0 ratings