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(proxy/prerequests): fix duplicate key behavior, fallthrough #23227

Merged
merged 5 commits into from
Aug 10, 2022

Conversation

flotwig
Copy link
Contributor

@flotwig flotwig commented Aug 9, 2022

  • Closes

User facing changelog

  • Fixed an issue introduced in 10.3.0 where network logs could be missing certain information or cause certain requests to be delayed by 500ms.

Additional details

  • Performance fixes in fix: Time out unmatched prerequests in proxy to avoid leaking memory #22462 caused a couple of unintended changes:
    • Missing return statement on line 77 here causes a matched prerequest to be queued anyways:
      addPending (browserPreRequest: BrowserPreRequest) {
      metrics.browserPreRequestsReceived++
      const key = `${browserPreRequest.method}-${browserPreRequest.url}`
      if (this.pendingRequests[key]) {
      debugVerbose('Incoming pre-request %s matches pending request. %o', key, browserPreRequest)
      clearTimeout(this.pendingRequests[key].timeout)
      this.pendingRequests[key].callback(browserPreRequest)
      delete this.pendingRequests[key]
      }
      debugVerbose('Caching pre-request %s to be matched later. %o', key, browserPreRequest)
      this.pendingPreRequests[key] = browserPreRequest
      this.prerequestTimestamps[key] = Date.now()
      }
    • More impactful, the Record<string, ...> data structure would clobber any duplicate url+method requests/pre-requests, which could manifest itself in incorrect pre-request data or unintended delays of requests by 500ms.
      • Replaced this with a StackMap which supports duplicate keys and .pop by key.

Steps to test

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)
  • [na] Has a PR for user-facing changes been opened in cypress-documentation?
  • [na] Have API changes been updated in the type definitions?

@cypress-bot
Copy link
Contributor

cypress-bot bot commented Aug 9, 2022

Thanks for taking the time to open a PR!

@flotwig flotwig requested a review from BlueWinds August 9, 2022 22:13
Comment on lines 9 to 12
function expectPendingCounts (pendingRequests: number, pendingPreRequests: number) {
expect(preRequests.pendingRequests._length()).to.eq(pendingRequests, 'wrong number of pending requests')
expect(preRequests.pendingPreRequests._length()).to.eq(pendingPreRequests, 'wrong number of pending prerequests')
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

You can run this spec and replace this fn with:

  function expectPendingCounts (pendingRequests: number, pendingPreRequests: number) {
    expect(Object.entries(preRequests.pendingRequests).length).to.eq(pendingRequests, 'wrong number of pending requests')
    expect(Object.entries(preRequests.pendingPreRequests).length).to.eq(pendingPreRequests, 'wrong number of pending prerequests')
  }

to see the previous behavior, all 4 tests failed on this assertion with a leak.

@cypress
Copy link

cypress bot commented Aug 9, 2022



Test summary

37846 0 469 0Flakiness 4


Run details

Project cypress
Status Passed
Commit ba215e0
Started Aug 10, 2022 3:52 PM
Ended Aug 10, 2022 4:13 PM
Duration 21:07 💡
OS Linux Debian - 11.3
Browser Multiple

View run in Cypress Dashboard ➡️


Flakiness

cypress/proxy-logging.cy.ts Flakiness
1 Proxy Logging > request logging > xhr log has response body/status code when xhr response is logged second
2 Proxy Logging > request logging > xhr log has response body/status code when xhr response is logged second
e2e/origin/commands/assertions.cy.ts Flakiness
1 cy.origin assertions > #consoleProps > .should() and .and()
next.cy.ts Flakiness
1 Working with next-12.1.6 > should detect new spec

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

flotwig and others added 2 commits August 9, 2022 22:38
@flotwig flotwig marked this pull request as ready for review August 9, 2022 23:51
@flotwig flotwig requested a review from a team as a code owner August 9, 2022 23:51
@flotwig flotwig requested a review from BlueWinds August 10, 2022 15:43
Copy link
Collaborator

@ryanthemanuel ryanthemanuel left a comment

Choose a reason for hiding this comment

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

I initially left a comment, but I had misunderstood what was going on. I'm pretty clear now. Looks good!

@flotwig flotwig merged commit 9bc3715 into develop Aug 10, 2022
@flotwig flotwig deleted the prerequest-fixes branch August 10, 2022 19:16
@cypress-bot
Copy link
Contributor

cypress-bot bot commented Aug 15, 2022

Released in 10.5.0.

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

@cypress-bot cypress-bot bot locked as resolved and limited conversation to collaborators Aug 15, 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