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

fix: Time out unmatched prerequests in proxy to avoid leaking memory #22462

Merged
merged 17 commits into from
Jun 23, 2022

Conversation

BlueWinds
Copy link
Contributor

@BlueWinds BlueWinds commented Jun 22, 2022

User facing changelog

No user facing impact.

Additional details

Refactored the prerequest proxy logic to be easier to follow. It now uses plain javascript objects with a string key to identify prerequests and requests, and creates fewer closure functions.

It also sweeps unmatched prerequests more than 10s old, and doesn't retain references to requests in the metrics object, ensuring that we're not leaking memory. I have not verified that this occurs in scenarios that #22460 doesn't already address, but I consider the refactor and minor performance gain to be worthwhile even with that PR making it in.

This should be considered a companion to, but not replacement for #22460. That PR has better performance in the case of data urls by catching them much sooner. This refactor and update is aimed more at readability, and ensuring we don't leak memory in other situations (which may or may not be happening).

Steps to test

This PR does not require manual testing. Our proxy logic is extensively tested with e2e and unit tests.

Run the unit tests for the proxy package. Existing tests are ~1% faster according to mocha, which is hard to notice because they're already quite fast. (this PR does add a couple of additional tests covering existing and new functionality, so total test time is longer than before on my machine).

How has the user experience changed?

PR Tasks

  • Have tests been added/updated?
  • Has the original issue (or this PR, if no issue exists) been tagged with a release in ZenHub? (user-facing changes only)
  • [n/a] Has a PR for user-facing changes been opened in cypress-documentation?
  • [n/a] Have API changes been updated in the type definitions?

@BlueWinds BlueWinds requested a review from a team as a code owner June 22, 2022 22:20
@cypress-bot
Copy link
Contributor

cypress-bot bot commented Jun 22, 2022

Thanks for taking the time to open a PR!

@BlueWinds BlueWinds requested review from AtofStryker and removed request for a team June 22, 2022 22:20
@BlueWinds BlueWinds requested a review from tgriesser as a code owner June 22, 2022 22:38
@emilyrohrbough
Copy link
Member

emilyrohrbough commented Jun 22, 2022

Could this have any impact on cy.route() or cy.intercept() if people are leverage cy.wait() and extend the default time to check against long scripts to resolve? 10 seconds seems quite lengthy so I could asking a totally random question that's not related whats-so-ever.

@BlueWinds
Copy link
Contributor Author

Could this have any impact on cy.route() or cy.intercept() if people are leverage cy.wait() and extend the default time to check against long scripts to resolve? 10 seconds seems quite lengthy so I could asking a totally random question that's not related whats-so-ever.

This prerequest/request pair in this context is a CDP event "The browser says it's about to make a request" and "the server received a request from the browser". It's a tight internal loop, to map these two events together. Usually takes a millisecond or two, and it'd only be slowed down my an overloaded CPU, not by user-supplied timeouts / cypress commands.

@cypress
Copy link

cypress bot commented Jun 22, 2022



Test summary

37681 0 456 0Flakiness 12


Run details

Project cypress
Status Passed
Commit e78aa7e
Started Jun 23, 2022 4:58 PM
Ended Jun 23, 2022 5:17 PM
Duration 18:13 💡
OS Linux Debian - 10.11
Browser Multiple

View run in Cypress Dashboard ➡️


Flakiness

actions/click.cy.js Flakiness
1 ... > scroll-behavior > can scroll to and click elements in html with scroll-behavior: smooth
net_stubbing.cy.ts Flakiness
1 network stubbing > waiting and aliasing > should handle aborted requests
xhr.cy.js Flakiness
1 ... > no status when request isnt forced 404
2 ... > logs request + response headers
3 ... > logs Method, Status, URL, and XHR
This comment includes only the first 5 flaky tests. See all 12 flaky tests in the Cypress Dashboard.

This comment has been generated by cypress-bot as a result of this project's GitHub integration settings. You can manage this integration in this project's settings in the Cypress Dashboard

@BlueWinds BlueWinds removed the request for review from tgriesser June 22, 2022 23:50
@BlueWinds
Copy link
Contributor Author

(Removed TIm as reviewer, it added him automatically when I accidentally included some GQL files I hadn't intended to touch)

@DJSdev
Copy link
Contributor

DJSdev commented Jun 23, 2022

Just wanted to drop in and say this refactor is great work!

Co-authored-by: Emily Rohrbough <emilyrohrbough@users.noreply.github.com>
packages/proxy/lib/http/util/prerequests.ts Outdated Show resolved Hide resolved
packages/proxy/lib/http/util/prerequests.ts Outdated Show resolved Hide resolved
packages/proxy/lib/http/util/prerequests.ts Outdated Show resolved Hide resolved
packages/proxy/lib/http/util/prerequests.ts Show resolved Hide resolved
packages/proxy/lib/http/util/prerequests.ts Outdated Show resolved Hide resolved
Blue F and others added 3 commits June 23, 2022 09:04
@AtofStryker AtofStryker self-requested a review June 23, 2022 16:16
@BlueWinds BlueWinds merged commit 172c364 into develop Jun 23, 2022
@BlueWinds BlueWinds deleted the issue-17853-prerequest-timeout branch June 23, 2022 17:12
tgriesser added a commit that referenced this pull request Jun 24, 2022
…esser/CLOUD-577-spec-list-display-latest-runs-batching

* muaz/CLOUD-577-spec-list-display-latest-runs:
  fix: Update "Request Access" button state after requesting access (ACI) (#22499)
  feat: Support "Queued" latest run status (#22497)
  fix: remove ctx.cloud.reset in tests, handle infinite loop in stale results (#22483)
  chore: add reporter webpack to gulp watch script (#22386)
  fix: Increase timeout for npm-webpack-dev-server tests (#22489)
  fix: Time out unmatched prerequests in proxy to avoid leaking memory (#22462)
  fix: Sort results in findCrossOriginLogs test helper to deterministic (#22481)
  fix: memory leak caused by storing base64 encoded files recieved by CDP `Network.requestWillBeSent` (#22460)
  fix: Improve cross-origin cookie handling (#22320)
  feat: Add button to clear value from search fields (#22202)
  chore: Add test to verify settings panels are collapsed by default (#22382)
  fix: process_profiler follow up work for v10 (#22363)
  chore: Update Chrome (stable) to 103.0.5060.53 (#22441)
  refactor: use design system windicss config (#21503)
  chore: update readme logo (#22433)
  chore: Update Chrome (beta) to 103.0.5060.53 (#22351)
  chore: updating version (#22432)
  Trigger Build
@cypress-bot
Copy link
Contributor

cypress-bot bot commented Jun 28, 2022

Released in 10.3.0.

This comment thread has been locked. If you are still experiencing this issue after upgrading to
Cypress v10.3.0, please open a new issue.

@cypress-bot cypress-bot bot locked as resolved and limited conversation to collaborators Jun 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants