Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: Client network socket disconnected before secure TLS connection was established #6482

Closed
actuallyReallyAlex opened this issue Feb 17, 2020 · 13 comments
Assignees

Comments

@actuallyReallyAlex
Copy link

Current behavior:

Attempt to cy.visit() a url behind a corp proxy (successfully configured, as I can visit other websites through Cypress through the proxy), that quickly redirects to another site. I believe it opens and closes a websocket very quickly, and this is causing Cypress (or one of it's dependencies) to throw an error.

No network request is even logged in the console. In the debug logs, this request and error can be seen as Cypress retries the same request over and over again until timeout.

cypress:network:agent addRequest called { isHttps: true, href: 'CONFIDENTIAL URL :)' } +14s
  cypress:network:agent got family { family: undefined, href: 'CONFIDENTIAL URL :)' } +8ms
  cypress:network:agent Creating proxied socket for CONFIDENTIAL URL :) through CONFIDENTIAL PROXY :) +3ms
  cypress:network:connect successfully connected { opts: { port: 3128, host: 'CONFIDENTIAL HOST :)', useTls: false, getDelayMsForRetry: [Function] }, iteration: 0 } +14s
  cypress:network:agent Proxy socket for CONFIDENTIAL URL :) established +156ms
  cypress:server:events got request for event: get:project:status, { path: 'CONFIDENTIAL PATH :)' } +10s
  cypress:server:project get project status for client id undefined at path CONFIDENTIAL PATH :) +10s
  cypress:server:project no project id +2ms
  cypress:server:events sending ipc data { type: 'get:project:status', data: { id: 0.34702146401190315, data: { path: 'CONFIDENTIAL PATH :)', state: 'VALID' } } } +6ms
  cypress:server:request received an error making http request { auth: null, failOnStatusCode: true, retryOnNetworkFailure: true, retryOnStatusCodeFailure: false, method: 'GET', body: null, headers: { accept: 'text/html,*/*', 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like
Gecko) Chrome/79.0.3945.117 Safari/537.36' }, timeout: 30000, gzip: false, url: 'CONFIDENTIAL URL :)', onBeforeReqInit: [Function: runPhase], requestId: 'request2', retryIntervals: [ 0, 1000, 2000, 2000 ], delaysRemaining: [], err: Error: Client network socket disconnected before secure TLS connection was established     at connResetException (internal/errors.js:559:14)     at TLSSocket.onConnectEnd (_tls_wrap.js:1357:19)     at Object.onceWrapper (events.js:291:20)     at TLSSocket.emit (events.js:208:15)     at endReadableNT (_stream_readable.js:1168:12)     at processTicksAndRejections (internal/process/task_queues.js:77:11) { code: 'ECONNRESET', path: null, host: 'dev2-icc.us.bank-dns.com', port: '15775', localAddress: undefined } } +14s
  cypress:server:request exhausted all attempts retrying request { auth: null, failOnStatusCode: true, retryOnNetworkFailure: true, retryOnStatusCodeFailure: false, method: 'GET', body: null, headers: { accept: 'text/html,*/*', 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.117 Safari/537.36' }, timeout: 30000, gzip: false, url: 'CONFIDENTIAL URL :)', onBeforeReqInit: [Function: runPhase], requestId: 'request2', retryIntervals: [ 0, 1000, 2000, 2000 ], delaysRemaining: [], err: Error: Client network socket disconnected before secure TLS connection was established     at connResetException (internal/errors.js:559:14)     at TLSSocket.onConnectEnd (_tls_wrap.js:1357:19)     at Object.onceWrapper (events.js:291:20)     at TLSSocket.emit (events.js:208:15)     at endReadableNT (_stream_readable.js:1168:12)     at processTicksAndRejections (internal/process/task_queues.js:77:11) { code: 'ECONNRESET', path: null, host: 'dev2-icc.us.bank-dns.com', port: '15775', localAddress: undefined } } +6ms

Desired behavior:

Visit the site and allow for this socket hangup to occur.

Test code to reproduce

Very difficult to give you something to reproduce here - would need a corp proxy, proxy setup, dns, and a server to redirect. I understand if this is not helpful, but I was hoping this has been seen before.

Versions

Cypress v4.0.1
Windows 10
Error seen in Chrome, FireFox, and Electron

Seems very similar to #2295 and possibly #4764

If I don't have access to the server itself, is there a way I can set a header for the connection within Cypress?

I've also tried setting up a middle server to redirect to the real server and telling Cypress to hit the middle server, but getting the same results.

@flotwig
Copy link
Contributor

flotwig commented Feb 18, 2020

Hey @alexlee-dev, to make sure I have this right:

  1. You have a HTTP proxy set up.
  2. Your test cy.visits a website over HTTPS (proxied)
  3. That website redirects via HTTP 3xx to another HTTPS URL on a different domain (also proxied)
  4. The cy.visit fails with the error "Error: Client network socket disconnected before secure TLS connection was established"

Is that correct?

@flotwig
Copy link
Contributor

flotwig commented Feb 18, 2020

If I don't have access to the server itself, is there a way I can set a header for the connection within Cypress?

You can set headers with cy.visit:

cy.visit({
	url: 'http://google.com',
	headers: {
		'some-header': 'foo'
	}
})

@flotwig flotwig self-assigned this Feb 18, 2020
@actuallyReallyAlex
Copy link
Author

@flotwig Thanks for the quick response :)

Hey @alexlee-dev, to make sure I have this right:

  1. You have a HTTP proxy set up.
  2. Your test cy.visits a website over HTTPS (proxied)
  3. That website redirects via HTTP 3xx to another HTTPS URL on a different domain (also proxied)
  4. The cy.visit fails with the error "Error: Client network socket disconnected before secure TLS connection was established"

Is that correct?

  1. true
  2. true
  3. false - I originally thought it was a redirect. Now it looks like what happens is you hit URL#1, and it loads the React application, which then takes in the query string from URL#1 and hits URL#2, at which point React Router takes the response from that request and sets the window.location as URL#3.
  4. true

I'm thinking that somewhere a websocket is closed too quickly in-between hitting URL#1, the endpoint of URL#2 and changing the window location to URL#3.

I would set a header, but I'm not sure which one would satisfy the socket closing error.
Socket: "Close" ?

@flotwig
Copy link
Contributor

flotwig commented Feb 18, 2020

Does your application in step (2) create a websocket, or are you referring to the websocket that Cypress creates & uses internally?

Is the new URL on step (2) on the same domain as the URL from step (1)? Maybe you could give me some pseudo-URLs to try.

You could try sending Connection: close, but it seems like a shot in the dark 😅

@actuallyReallyAlex
Copy link
Author

I believe it's just a simple post request to a REST server. I don't explicitly see any websocket created by the application. My inclination to think it's a websocket issue comes from that being the error message displayed when reading the debug logs in the cypress terminal.

Yes, the URL on step 2 is on the same domain as the URL from step 1. However, I believe the server is making a request to an outside domain before sending back the response (not sure if that is relevant though).

URL#1 (My Domain) -> Returns React Application -> React App Hits URL#2 (My Domain) -> Server listens for request to URL#2 and makes request to Service (Not My Domain) -> Server sends back response to React App -> React App uses React Router to redirect to a new page (My Domain).

I can try and do the same logic as above with a dummy server in a repo if you'd like.

@flotwig
Copy link
Contributor

flotwig commented Feb 18, 2020

Yeah, that would be super helpful, then I can reproduce the issue and try to debug it. Thanks!

@actuallyReallyAlex
Copy link
Author

@flotwig I've created a repo so you can reproduce the issue. Steps for installing and running the servers are in the README at the root. Let me know if you have any questions! Thanks.

https://github.com/alexlee-dev/cypress-issue-6482

It works without a proxy. It fails with a proxy.

Error: ESOCKETTIMEDOUT

@cypress-bot cypress-bot bot added the stage: needs investigating Someone from Cypress needs to look at this label Feb 19, 2020
@actuallyReallyAlex
Copy link
Author

@flotwig Any progress on this one? Or any direction toward debugging I could be going towards?

I understand you guys are busy though.

Thanks!

@flotwig
Copy link
Contributor

flotwig commented Feb 25, 2020

@alexlee-dev are you using some kind of development proxy?

I tried testing your project, it works for me both with and without a proxy. I used https://github.com/cypress-io/debugging-proxy to stand up a proxy locally, and ran NO_PROXY='<-loopback>' HTTP_PROXY=http://localhost:1337 npm run cypress-run

@actuallyReallyAlex
Copy link
Author

It's some annoying corp proxy that I don't have much control over or insight into unfortunately :(

What does NO_PROXY='<loopback>' do ? Is that specific to debugging-proxy or will Cypress parse that in a specific way?

@flotwig
Copy link
Contributor

flotwig commented Feb 25, 2020

Since my proxy is on localhost, that tells requests to still use the proxy, even for requests that go over localhost. Or else the debugging proxy would have no effect.

@cypress-bot cypress-bot bot added stage: needs information Not enough info to reproduce the issue and removed stage: needs investigating Someone from Cypress needs to look at this labels Feb 26, 2020
@CarstenHS
Copy link

CarstenHS commented Feb 28, 2020

This could be due to missing proxy auth. In mycase I missed protocol and basic auth of the HTTP_PROXY, hence it could be this:

HTTP_PROXY=http://<user>:<pass>@<host>:<port>

Furthermore as I requested HTTPS it was the HTTPS_PROXY that needed to be set.

Feedback: it would be nice with more details on the TLS connection error - i.e. "missing auth"..

@actuallyReallyAlex
Copy link
Author

@flotwig , @CarstenHS -- Ok, so I did a lot more digging. It turns out it had something to do with a weird setup on the particular server that was in the development environment I was using. I ended up having a coworker configure a different server and now it's working without an error.

I'll close this for now, as I'm convinced it's my workplace's config and not Cypress itself.

Thank you for the help and sorry for the trouble.

@jennifer-shehane jennifer-shehane removed the stage: needs information Not enough info to reproduce the issue label Mar 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants