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

Always pass NODE_OPTIONS with max-http-header-size #5452

Merged
merged 11 commits into from Oct 25, 2019

Conversation

flotwig
Copy link
Contributor

@flotwig flotwig commented Oct 24, 2019

Reverted in #5522


User facing changelog

Fixes a regression in 3.5.0 where the maximum size of an HTTP header or cy.route() stub body was limited to 8kb and requests would fail with HTTP error 431.

Additional details

  • Passes --max-http-header-size=${1024 * 1024} in NODE_OPTIONS environment var from CLI
    • Passing it as a CLI arg (the way we thought it worked) does not seem to work with vanilla Electron binary or with built Cypress binary, so this is the only way
    • By ordering it before the user-supplied NODE_OPTIONS, the user can still override this via NODE_OPTIONS if they choose
  • Makes 4_xhr_spec e2e test go through CLI so it can run a test with this max http header size set
  • User's original NODE_OPTIONS are backed up and restored once Electron successfully launches so that node processes launched by Cypress on behalf of the user have desired NODE_OPTIONS

How has the user experience changed?

N/A

PR Tasks

  • Have tests been added/updated?

@cypress-bot
Copy link
Contributor

cypress-bot bot commented Oct 24, 2019

Thanks for the contribution! Below are some guidelines Cypress uses when doing PR reviews.

  • Please write [WIP] in the title of your Pull Request if your PR is not ready for review - someone will review your PR as soon as the [WIP] is removed.
  • Please familiarize yourself with the PR Review Checklist and feel free to make updates on your PR based on these guidelines.

PR Review Checklist

If any of the following requirements can't be met, leave a comment in the review selecting 'Request changes', otherwise 'Approve'.

User Experience

  • The feature/bugfix is self-documenting from within the product.
  • The change provides the end user with a way to fix their problem (no dead ends).

Functionality

  • The code works and performs its intended function with the correct logic.
  • Performance has been factored in (for example, the code cleans up after itself to not cause memory leaks).
  • The code guards against edge cases and invalid input and has tests to cover it.

Maintainability

  • The code is readable (too many nested 'if's are a bad sign).
  • Names used for variables, methods, etc, clearly describe their function.
  • The code is easy to understood and there are relevant comments explaining.
  • New algorithms are documented in the code with link(s) to external docs (flowcharts, w3c, chrome, firefox).
  • There are comments containing link(s) to the addressed issue (in tests and code).

Quality

  • The change does not reimplement code.
  • There's not a module from the ecosystem that should be used instead.
  • There is no redundant or duplicate code.
  • There are no irrelevant comments left in the code.
  • Tests are testing the code’s intended functionality in the best way possible.

Internal

  • The original issue has been tagged with a release in ZenHub.

@flotwig
Copy link
Contributor Author

flotwig commented Oct 24, 2019

Hm, Mac kitchensink is failing because it only has support for Node 11. Since it's in dev mode, it's launching node instead of electron and failing because 11 doesn't have this option. Might be better to just figure out all the places where this can be explicitly passed and pass it...

EDIT: Actually, --max-http-header-size doesn't seem to have any impact when passed to the package app. It only works if supplied in NODE_OPTIONS, which is also the only documented way I could find to pass Node CLI options to Node.js.

@flotwig flotwig changed the title [WIP] Always pass NODE_OPTIONS with max-http-header-size Always pass NODE_OPTIONS with max-http-header-size Oct 24, 2019
@andrew-codes andrew-codes self-requested a review October 25, 2019 20:37
Copy link
Contributor

@andrew-codes andrew-codes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It appears like appropriate tests were added and I was able to follow the changes in relation to the PR's functionality. The whitespace changes made it a little hard to discern for a single file, but not impossible. I imagine having those whitespace changes would be ideal given what they were.

Copy link
Member

@jennifer-shehane jennifer-shehane left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ran this branch in the services repo - where basically all of their tests were failing with this 431 error - they are now passing. I didn't review the code.

if (options.dev && nodeVersion < 12) {
// `node` is used when --dev is passed, so this won't work if Node is too old
logger.warn('(dev-mode warning only) NODE_OPTIONS=--max-http-header-size could not be set. See https://github.com/cypress-io/cypress/pull/5452')

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will the new max-header log in DEBUG logs for all of our users? Cause I'd like any new options to be logged in their DEBUG logs for future debugging.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not logged anywhere :/ But, it should always be passed, as this is the only condition where it wouldn't be.

@jennifer-shehane jennifer-shehane merged commit 978d97e into develop Oct 25, 2019
flotwig added a commit that referenced this pull request Oct 29, 2019
flotwig added a commit that referenced this pull request Mar 11, 2020
* cli: set NODE_OPTIONS=--max-http-header-size=1024*1024 on spawn

* electron: remove redundant max-http-header-size

* server: add useCli option to make e2e tests go thru cli

* server: add test for XHR with body > 100kb via CLI

* clean up conditional

* cli: don't pass --max-http-header-size in dev w node < 11.10

* add original_node_options to restore o.g. user node_options

* force no color
flotwig added a commit that referenced this pull request Mar 18, 2020
* Detect if NODE_OPTIONS are present in binary; if not, respawn

* Always reset NODE_OPTIONS, even if no ORIGINAL_

Co-authored-by: Andrew Smith <andrew@andrew.codes>

* Exit with correct code # from stub process

* Clean up based on Brian's feedback

* how process.versions is null, i have no idea, but it is

* add repro for invalid header char

* Always pass NODE_OPTIONS with max-http-header-size (#5452)

* cli: set NODE_OPTIONS=--max-http-header-size=1024*1024 on spawn

* electron: remove redundant max-http-header-size

* server: add useCli option to make e2e tests go thru cli

* server: add test for XHR with body > 100kb via CLI

* clean up conditional

* cli: don't pass --max-http-header-size in dev w node < 11.10

* add original_node_options to restore o.g. user node_options

* force no color

* Revert "Use websockets to stub large XHR response bodies instead of hea… (#5525)"

This reverts commit 249db45.

* fix yarn.lock

* update 4_xhr_spec snapshot

* make 6_visit_spec reproduce invalid header char error

* pass --http-parser=legacy

* still set headers if an ERR_INVALID_CHAR is raised

* add --http-parser=legacy in some more places

* update http_requests_spec

* readd spawn_spec

* improve debug logging

* remove unnecessary changes

* cleanup

* revert yarn.lock to develop

* use cp.spawn, not cp.fork

to work around the Electron patch: https://github.com/electron/electron/blob/39baf6879011c0fe8cc975c7585567c7ed0aeed8/patches/node/refactor_alter_child_process_fork_to_use_execute_script_with.patch

Co-authored-by: Andrew Smith <andrew@andrew.codes>
@flotwig flotwig deleted the issue-5431-431-error branch January 24, 2022 18:16
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

Successfully merging this pull request may close these issues.

None yet

3 participants