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: undo timeout change to fix performance regression #28075

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions cli/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
<!-- See the ../guides/writing-the-cypress-changelog.md for details on writing the changelog. -->
## 13.3.2

_Released 10/18/2023 (PENDING)_

**Bugfixes:**

- Fixed a performance regression where proxy correlation timeouts for requests in service workers were always hit causing slow downs. Fixes [#28054](https://github.com/cypress-io/cypress/issues/28054)

## 13.3.1

_Released 10/11/2023_
Expand Down
14 changes: 7 additions & 7 deletions packages/proxy/lib/http/util/prerequests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ class QueueMap<T> {

this.queues[queueKey].push(value)
}
shift (queueKey: string): T | undefined {
pop (queueKey: string): T | undefined {
const queue = this.queues[queueKey]

if (!queue) return

const item = queue.shift()
const item = queue.pop()

if (queue.length === 0) delete this.queues[queueKey]

Expand Down Expand Up @@ -95,7 +95,7 @@ export class PreRequests {
protocolManager?: ProtocolManagerShape

constructor (
requestTimeout = 2000,
requestTimeout = 500,
// 10 seconds
sweepInterval = 10000,
) {
Expand Down Expand Up @@ -134,7 +134,7 @@ export class PreRequests {
addPending (browserPreRequest: BrowserPreRequest) {
metrics.browserPreRequestsReceived++
const key = `${browserPreRequest.method}-${browserPreRequest.url}`
const pendingRequest = this.pendingRequests.shift(key)
const pendingRequest = this.pendingRequests.pop(key)

if (pendingRequest) {
const timings = {
Expand Down Expand Up @@ -174,7 +174,7 @@ export class PreRequests {

addPendingUrlWithoutPreRequest (url: string) {
const key = `GET-${url}`
const pendingRequest = this.pendingRequests.shift(key)
const pendingRequest = this.pendingRequests.pop(key)

if (pendingRequest) {
debugVerbose('Handling %s without a CDP prerequest', key)
Expand All @@ -200,7 +200,7 @@ export class PreRequests {

metrics.proxyRequestsReceived++
const key = `${req.method}-${req.proxiedUrl}`
const pendingPreRequest = this.pendingPreRequests.shift(key)
const pendingPreRequest = this.pendingPreRequests.pop(key)

if (pendingPreRequest) {
metrics.immediatelyMatchedRequests++
Expand All @@ -217,7 +217,7 @@ export class PreRequests {
return
}

const pendingUrlWithoutPreRequests = this.pendingUrlsWithoutPreRequests.shift(key)
const pendingUrlWithoutPreRequests = this.pendingUrlsWithoutPreRequests.pop(key)

if (pendingUrlWithoutPreRequests) {
metrics.immediatelyMatchedRequests++
Expand Down
35 changes: 18 additions & 17 deletions packages/proxy/test/unit/http/util/prerequests.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,28 +41,29 @@ describe('http/util/prerequests', () => {
cdpRequestWillBeSentReceivedTimestamp: 2,
})

const secondPreRequest: BrowserPreRequest = {
preRequests.addPending({
requestId: '1234',
url: 'foo',
method: 'GET',
headers: {},
resourceType: 'xhr',
originalResourceType: undefined,
cdpRequestWillBeSentTimestamp: 1,
cdpRequestWillBeSentReceivedTimestamp: performance.now() + performance.timeOrigin + 10000,
}
cdpRequestWillBeSentReceivedTimestamp: 2,
})

preRequests.addPending(secondPreRequest)
preRequests.addPending({
const thirdRequest: BrowserPreRequest = {
requestId: '1234',
url: 'foo',
method: 'GET',
headers: {},
resourceType: 'xhr',
originalResourceType: undefined,
cdpRequestWillBeSentTimestamp: 1,
cdpRequestWillBeSentReceivedTimestamp: 2,
})
cdpRequestWillBeSentReceivedTimestamp: performance.now() + performance.timeOrigin + 10000,
}

preRequests.addPending(thirdRequest)

expectPendingCounts(0, 3)

Expand All @@ -73,17 +74,17 @@ describe('http/util/prerequests', () => {
const { args } = cb.getCall(0)
const arg = args[0]

expect(arg.requestId).to.eq(secondPreRequest.requestId)
expect(arg.url).to.eq(secondPreRequest.url)
expect(arg.method).to.eq(secondPreRequest.method)
expect(arg.headers).to.deep.eq(secondPreRequest.headers)
expect(arg.resourceType).to.eq(secondPreRequest.resourceType)
expect(arg.originalResourceType).to.eq(secondPreRequest.originalResourceType)
expect(arg.cdpRequestWillBeSentTimestamp).to.eq(secondPreRequest.cdpRequestWillBeSentTimestamp)
expect(arg.cdpRequestWillBeSentReceivedTimestamp).to.eq(secondPreRequest.cdpRequestWillBeSentReceivedTimestamp)
expect(arg.requestId).to.eq(thirdRequest.requestId)
expect(arg.url).to.eq(thirdRequest.url)
expect(arg.method).to.eq(thirdRequest.method)
expect(arg.headers).to.deep.eq(thirdRequest.headers)
expect(arg.resourceType).to.eq(thirdRequest.resourceType)
expect(arg.originalResourceType).to.eq(thirdRequest.originalResourceType)
expect(arg.cdpRequestWillBeSentTimestamp).to.eq(thirdRequest.cdpRequestWillBeSentTimestamp)
expect(arg.cdpRequestWillBeSentReceivedTimestamp).to.eq(thirdRequest.cdpRequestWillBeSentReceivedTimestamp)
expect(arg.proxyRequestReceivedTimestamp).to.be.a('number')
expect(arg.cdpLagDuration).to.eq(secondPreRequest.cdpRequestWillBeSentReceivedTimestamp - secondPreRequest.cdpRequestWillBeSentTimestamp)
expect(arg.proxyRequestCorrelationDuration).to.eq(secondPreRequest.cdpRequestWillBeSentReceivedTimestamp - arg.proxyRequestReceivedTimestamp)
expect(arg.cdpLagDuration).to.eq(thirdRequest.cdpRequestWillBeSentReceivedTimestamp - thirdRequest.cdpRequestWillBeSentTimestamp)
expect(arg.proxyRequestCorrelationDuration).to.eq(thirdRequest.cdpRequestWillBeSentReceivedTimestamp - arg.proxyRequestReceivedTimestamp)

expectPendingCounts(0, 2)
})
Expand Down
Loading