cypress: Cypress is unable to load site in v3.5.0 due to "Parse Error"

Current behavior:

When attempting to resolve our site, Cypress throws an error. This was not an issue on older versions of Cypress. Our NGINX config is fairly vanilla and hasnt changed since we deployed it several months ago

error

CypressError: cy.visit() failed trying to load:

https://our-website.test.com/search-page

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: Parse Error

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: Parse Error
    at TLSSocket.socketOnData (_http_client.js:451:22)
    at TLSSocket.emit (events.js:194:13)
    at addChunk (_stream_readable.js:296:12)
    at readableAddChunk (_stream_readable.js:277:11)
    at TLSSocket.Readable.push (_stream_readable.js:232:10)
    at TLSWrap.onStreamRead (internal/stream_base_commons.js:165:17)


Because this error occurred during a 'before each' hook we are skipping the remaining tests in the current suite: 'Search Page tests'`

Desired behavior:

Our site loads on newer versions of Cypress (3.5.0) and up.

Steps to reproduce: (app code and test code)

example code:

/// <reference types="Cypress" />
describe('Search Page Tests', () => {
  beforeEach(() => {
    cy.visit('/search')
    })

    cy.get(`[data-qa='tabs-wrapper']`).get(`[data-qa='tab']`).contains('red').as('redButton')    
    cy.get(`[data-qa='tabs-wrapper']`).get('[data-qa="tab"]').contains('blue').as('blueButton')
  })

  it('visit the search page and search for buttons', () => {
    cy.getById('searchGoToHomeButton')
      .should('have.attr', 'href', '/home')
  });

Steps to reproduce.

npx cypress open

Click spec from GUI and let test start. Error is thrown immediately upon attempting to resolve the page.

Versions

v3.5.0

Cypress desktop, v3.5.0, MAcOS 10.13.6, Electron(Chrome v78)

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 2
  • Comments: 44 (15 by maintainers)

Most upvoted comments

After doing some investigation into the “Parse Error: Invalid header value char”, it comes down to a change in Node.js that was made in Node.js 11.5.0: nodejs/node#24730

The llhttp HTTP parser replaced the old http_parser HTTP parser. The newer one is more maintainable; however, it also seems to be much stricter about what can be in an HTTP header. Since Cypress uses Node’s HTTP library to proxy requests to your site, invalid characters in the header will now give this error.

In Cypress 3.5.0, the bundled Node.js version was upgraded to > 11.5.0 (#5849), introducing this bug.

Here is a bug in the Node.js repo talking about this issue with llhttp and some proposed fixes: nodejs/node#30573

I believe that, in the meantime, we may be able to pass the --http-parser=legacy option to opt out of using the new llhttp parser. I will work on creating a test that reproduces the “Invalid header value char” issue as well as a fix.

In the meantime, a workaround would be to ensure that the headers sent by your server do not contain any special characters that are illegal in an HTTP header.

@gabbersepp I cannot share details of scripts or website over here, however I have already sent an email with some details to cypress support team.

We are also getting exactly same issue. With cypress version 3.4.1 every application works fine, however when we try to upgrade to latest versions (3.6.0+) then cypress is not able access the site (throwing the same error shared bytes @tmonteith ).

Apparently, something changed between 3.4.1 to latest versions of cypress that is causing issue. Note that we are also using ngnix and same configurations that work fine with c.ypress 3.4.1, do not work with cypress 3.6.0. @jennifer-shehane

Taking a look at the above posts, I can see I am having the same issue as other people. Is there a work around for this issue?

@natkrish We are waiting for https://github.com/electron/electron/pull/21694 to be released in Electron 9 so we can use it. Once we can use --http-parser=legacy, we can fix this finally.

In the meantime, the only workaround is to update your web server to send headers that do not contain non-printable ASCII characters.

@flotwig I put up an example that throws the “Parse Error: Invalid header value char” error on just a simple cy.visit().

@flotwig Using 3.8.0 we get the same “Parse Error” in some environments, but not others. Here’s the Set-Cookie header for the one that does not work

set-cookie: AWSALB=0GzYs2kzoyI4H5bZBHOUQHEtlZzm2DdrV2TXptF0/BHF3tpdtTFhqTTfCv7aBCb+Vid4UN1W2JN1chRqekIi605s2KqWERTn6OxJerAZQti79gd0DAqCBuft2Qez; Expires=Sun, 22 Dec 2019 21:03:30 GMT; Path=/

while this one does work with no problems

Set-Cookie: AWSALB=MLuupbHkQ8eUksOj0T/StnqF9Xh7Rr8NUro7WGQTD9eaW5NQiuIDh5uso1LjYZ/XgDkqgB2CvgCjm/pcZ9aMhJzyRbA8qwRQ43NNNJzTN/ch0NnsYZoWAvTHcjM6; Expires=Sun, 22 Dec 2019 21:04:15 GMT; Path=/

Could it be the lowercase format?

Edit. I just saw that with the latest update we’re now getting a “Parse Error: Invalid header value char” and not just the “Parse Error” we had from 3.5.0 and up.

CypressError: cy.request() failed trying to load:

https://our-website.com/login

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: Parse Error: Invalid header value char

-----------------------------------------------------------

The request we sent was:

Method: POST
URL: https://our-website.com/login

-----------------------------------------------------------

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:

RequestError: Error: Parse Error: Invalid header value char
    at new RequestError (/Users/792276/Library/Caches/Cypress/3.8.0/Cypress.app/Contents/Resources/app/packages/server/node_modules/request-promise-core/lib/errors.js:14:15)
    at Request.plumbing.callback (/Users/792276/Library/Caches/Cypress/3.8.0/Cypress.app/Contents/Resources/app/packages/server/node_modules/request-promise-core/lib/plumbing.js:87:29)
    at Request.RP$callback [as _callback] (/Users/792276/Library/Caches/Cypress/3.8.0/Cypress.app/Contents/Resources/app/packages/server/node_modules/request-promise-core/lib/plumbing.js:46:31)
    at self.callback (/Users/792276/Library/Caches/Cypress/3.8.0/Cypress.app/Contents/Resources/app/packages/server/node_modules/request/request.js:185:22)
    at Request.emit (events.js:203:13)
    at Request.onRequestError (/Users/792276/Library/Caches/Cypress/3.8.0/Cypress.app/Contents/Resources/app/packages/server/node_modules/request/request.js:877:8)
    at ClientRequest.emit (events.js:203:13)
    at TLSSocket.socketOnData (_http_client.js:456:9)
    at TLSSocket.emit (events.js:203:13)
    at addChunk (_stream_readable.js:295:12)
    at readableAddChunk (_stream_readable.js:276:11)
    at TLSSocket.Readable.push (_stream_readable.js:210:10)
    at TLSWrap.onStreamRead (internal/stream_base_commons.js:166:17)


Because this error occurred during a 'before each' hook we are skipping the remaining tests in the current suite: 'Login test'