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

Infinite recursion in net-stubbing/lib/server/middleware/request.js #22693

Closed
eirikur-grid opened this issue Jul 6, 2022 · 5 comments · Fixed by #22940
Closed

Infinite recursion in net-stubbing/lib/server/middleware/request.js #22693

eirikur-grid opened this issue Jul 6, 2022 · 5 comments · Fixed by #22940
Assignees

Comments

@eirikur-grid
Copy link
Contributor

eirikur-grid commented Jul 6, 2022

Current behavior

We run our cypress tests on CircleCI, distributing the tests among several runners. Sometimes we get a failure like this one:

RangeError: Maximum call stack size exceeded
    at RegExp.get source [as source] (<anonymous>:null:null)
    at RegExp.toString (<anonymous>:null:null)
    at equalByTag (/root/.cache/Cypress/9.6.0/Cypress/resources/app/node_modules/lodash/lodash.js:5786:35)
    at baseIsEqualDeep (/root/.cache/Cypress/9.6.0/Cypress/resources/app/node_modules/lodash/lodash.js:3357:13)
    at baseIsEqual (/root/.cache/Cypress/9.6.0/Cypress/resources/app/node_modules/lodash/lodash.js:3316:14)
    at equalObjects (/root/.cache/Cypress/9.6.0/Cypress/resources/app/node_modules/lodash/lodash.js:5872:43)
    at baseIsEqualDeep (/root/.cache/Cypress/9.6.0/Cypress/resources/app/node_modules/lodash/lodash.js:3375:14)
    at baseIsEqual (/root/.cache/Cypress/9.6.0/Cypress/resources/app/node_modules/lodash/lodash.js:3316:14)
    at baseIsMatch (/root/.cache/Cypress/9.6.0/Cypress/resources/app/node_modules/lodash/lodash.js:3433:19)
    at /root/.cache/Cypress/9.6.0/Cypress/resources/app/node_modules/lodash/lodash.js:3603:37
    at baseFindIndex (/root/.cache/Cypress/9.6.0/Cypress/resources/app/node_modules/lodash/lodash.js:816:11)
    at Function.findIndex (/root/.cache/Cypress/9.6.0/Cypress/resources/app/node_modules/lodash/lodash.js:7322:14)
    at getRouteForRequest (/root/.cache/Cypress/9.6.0/Cypress/resources/app/packages/net-stubbing/lib/server/route-matching.js:105:77)
    at populateMatchingRoutes (/root/.cache/Cypress/9.6.0/Cypress/resources/app/packages/net-stubbing/lib/server/middleware/request.js:45:67)
    at populateMatchingRoutes (/root/.cache/Cypress/9.6.0/Cypress/resources/app/packages/net-stubbing/lib/server/middleware/request.js:50:13)
    at populateMatchingRoutes (/root/.cache/Cypress/9.6.0/Cypress/resources/app/packages/net-stubbing/lib/server/middleware/request.js:50:13)
... and on and on and on

Desired behavior

Test should run without crashing

Test code to reproduce

I haven't found a reliable way to reproduce this. It's not always the same test that fails. However, the failures I've seen so far occur in tests with a beforeEach function that calls a utility method, which uses cy.intercept for a lot of our API routes.

Cypress Version

9.6.0

Other

No response

@cypress-bot cypress-bot bot added the stage: investigating Someone from Cypress is looking into this label Jul 11, 2022
@chrisbreiding
Copy link
Contributor

We'll need a reliable reproduction in order to debug this. Without that, we'll eventually have to close this issue until we can reproduce it. This does not mean that your issue is not happening - it just means that we do not have a path to move forward.

@cypress-bot cypress-bot bot added stage: awaiting response Potential fix was proposed; awaiting response and removed stage: investigating Someone from Cypress is looking into this labels Jul 12, 2022
@mjhenkes mjhenkes assigned mjhenkes and unassigned chrisbreiding Jul 19, 2022
@mjhenkes
Copy link
Member

Closing absent a reliable reproduction.

Please open a new issue with a reproducible example and link to this issue. Here are some tips for providing a Short, Self Contained, Correct, Example and our own Troubleshooting Cypress guide.

@mjhenkes mjhenkes closed this as not planned Won't fix, can't repro, duplicate, stale Jul 19, 2022
@eirikur-grid
Copy link
Contributor Author

I've been looking at the source code and I suspect I've found the root cause.
In route-matching.ts there's a function named getRouteForRequest. It accepts an optional prevRoute object, from which to start its search. This is achieved by:

const possibleRoutes = prevRoute ? orderedRoutes.slice(_.findIndex(orderedRoutes, prevRoute) + 1) : orderedRoutes

Looking at the lodash documentation for the findIndex function, I've surmised that it performs a deep comparison of objects, matching by value rather than reference. Hence, if there are two identical routes, it will match the first one, even if prevRoute is a reference to the second one.

I don't have my work laptop with me so I'm unable to whip up a repro right now.

@eirikur-grid
Copy link
Contributor Author

I'm working on a PR with a fix (and a test that would fail prior to the fix). Is it possible to re-open this issue or do I have to create a new one?

@cypress-bot cypress-bot bot added stage: needs review The PR code is done & tested, needs review stage: contributor pr in progress and removed stage: awaiting response Potential fix was proposed; awaiting response stage: needs review The PR code is done & tested, needs review labels Jul 26, 2022
@nagash77 nagash77 reopened this Jul 27, 2022
@cypress-bot cypress-bot bot added stage: needs review The PR code is done & tested, needs review and removed stage: routed to e2e-core labels Jul 28, 2022
@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 removed the stage: needs review The PR code is done & tested, needs review label Aug 15, 2022
@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.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants