cypress icon indicating copy to clipboard operation
cypress copied to clipboard

cy.visit() failed trying to load ESOCKETTIMEDOUT

Open otalandim opened this issue 4 years ago • 80 comments

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

otalandim avatar Apr 18 '20 16:04 otalandim

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!

jennifer-shehane avatar Apr 20 '20 07:04 jennifer-shehane

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

matzeeable avatar Apr 27 '20 10:04 matzeeable

@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"
      }
    })

midleman avatar May 23 '20 18:05 midleman

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

I'm using Chrome for the browser.

thedaviddias avatar Jul 07 '20 22:07 thedaviddias

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:*'

jennifer-shehane avatar Jul 27 '20 12:07 jennifer-shehane

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.

flotwig avatar Jul 27 '20 15:07 flotwig

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

jennifer-shehane avatar Jul 28 '20 04:07 jennifer-shehane

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.

matthewvandergrift avatar Aug 03 '20 17:08 matthewvandergrift

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

rubiii avatar Aug 10 '20 19:08 rubiii

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

flotwig avatar Aug 10 '20 19:08 flotwig

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.

rubiii avatar Aug 12 '20 09:08 rubiii

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.

adodge1 avatar Sep 02 '20 20:09 adodge1

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!

hagealex avatar Sep 07 '20 13:09 hagealex

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

🤷

rubiii avatar Sep 10 '20 10:09 rubiii

+1

getting the same issue via github

hslee16 avatar Sep 16 '20 17:09 hslee16

reverting to use cypress version 5.1.0 fixes the issue for me

hslee16 avatar Sep 16 '20 22:09 hslee16

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

gianmarxWebmapp avatar Sep 30 '20 15:09 gianmarxWebmapp

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.

myasul avatar Oct 21 '20 10:10 myasul

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).

hadalin avatar Oct 28 '20 13:10 hadalin

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)

cuzik avatar Nov 24 '20 12:11 cuzik

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",

cuzik avatar Nov 24 '20 12:11 cuzik

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

DoctorBenix avatar Dec 03 '20 09:12 DoctorBenix

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.

j-brammer avatar Dec 22 '20 21:12 j-brammer

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

theokrammer avatar Dec 23 '20 09:12 theokrammer

@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.

jennifer-shehane avatar Dec 30 '20 11:12 jennifer-shehane

, { responseTimeout: 31000 }

I tried this but still having the same issue. CI is still failing.

Chanuga avatar Jan 11 '21 05:01 Chanuga

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 scenario here

Chanuga avatar Jan 11 '21 06:01 Chanuga

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.

AshleyCao avatar Jan 12 '21 04:01 AshleyCao

I had the same problem, it was a server issue in my case. Just before to the frontend server, Cypress gets started. The following points need to be confirmed:

  • Frontend & Backend (if you need it) runs.
  • Cypress using the same host & port for testing on which frontend & backend is running. In GitHub CI it's better to use localhost for configuration instead of using 0.0.0.0
  • You should be aware that the yarn start command takes some time to start the server so that you can't run the cypress immediately after the start command.

DigneshGujarathi avatar Jan 12 '21 09:01 DigneshGujarathi

Same here:

https://github.com/estefafdez/cypress-template/runs/1682540584

Any update on this issue? Thanks team!

estefafdez avatar Jan 12 '21 09:01 estefafdez