react-instantsearch icon indicating copy to clipboard operation
react-instantsearch copied to clipboard

Maximum call stack size exceeded. Related to cache ?

Open YoannDelpierre opened this issue 6 years ago • 25 comments

Describe the bug 🐛

I got a 500 from SSR response. In my log I get RangeError: Maximum call stack size exceeded

To Reproduce 🔍

Infortunately, I have only this problem on production, not on staging or local.

If I restart my instance, everything back to normal. My memory was around 25%, I have a total o 2040 mo for my instance.

So I assume it's a problem on Algolia's cache.

Environment:

Next JS 9.3.4, Algolia javascript 4.1, ReactInstantSearch 6.4.0.

Never had the problem with Algolia 3.35.1 and ReactInstanceSearch 6.3.0

Additional context

14:30:24
RangeError: Maximum call stack size exceeded
RangeError: Maximum call stack size exceeded
14:30:24
at /usr/src/app/node_modules/react-instantsearch-core/dist/cjs/core/createInstantSearchManager.js:348:29
14:30:24
at Object.get (/usr/src/app/node_modules/@algolia/cache-common/dist/cache-common.cjs.js:43:27)
14:30:24
at client.search (/usr/src/app/node_modules/react-instantsearch-core/dist/cjs/core/createInstantSearchManager.js:344:50)
14:30:24
at /usr/src/app/node_modules/react-instantsearch-core/dist/cjs/core/createInstantSearchManager.js:348:29
14:30:24
at Object.get (/usr/src/app/node_modules/@algolia/cache-common/dist/cache-common.cjs.js:43:27)
14:30:24
at client.search (/usr/src/app/node_modules/react-instantsearch-core/dist/cjs/core/createInstantSearchManager.js:344:50)
14:30:24
at /usr/src/app/node_modules/react-instantsearch-core/dist/cjs/core/createInstantSearchManager.js:348:29
14:30:24
at Object.get (/usr/src/app/node_modules/@algolia/cache-common/dist/cache-common.cjs.js:43:27)
14:30:24
at client.search (/usr/src/app/node_modules/react-instantsearch-core/dist/cjs/core/createInstantSearchManager.js:344:50)
14:30:24
at /usr/src/app/node_modules/react-instantsearch-core/dist/cjs/core/createInstantSearchManager.js:348:29
14:30:24
at Object.get (/usr/src/app/node_modules/@algolia/cache-common/dist/cache-common.cjs.js:43:27)
14:30:24
at client.search (/usr/src/app/node_modules/react-instantsearch-core/dist/cjs/core/createInstantSearchManager.js:344:50)
14:30:24
at /usr/src/app/node_modules/react-instantsearch-core/dist/cjs/core/createInstantSearchManager.js:348:29
14:30:24
at Object.get (/usr/src/app/node_modules/@algolia/cache-common/dist/cache-common.cjs.js:43:27)
14:30:24
at client.search (/usr/src/app/node_modules/react-instantsearch-core/dist/cjs/core/createInstantSearchManager.js:344:50)
14:30:24
at /usr/src/app/node_modules/react-instantsearch-core/dist/cjs/core/createInstantSearchManager.js:348:29
14:30:24
at Object.get (/usr/src/app/node_modules/@algolia/cache-common/dist/cache-common.cjs.js:43:27)
14:30:24
at client.search (/usr/src/app/node_modules/react-instantsearch-core/dist/cjs/core/createInstantSearchManager.js:344:50)
14:30:24
at /usr/src/app/node_modules/react-instantsearch-core/dist/cjs/core/createInstantSearchManager.js:348:29
14:30:24
at Object.get (/usr/src/app/node_modules/@algolia/cache-common/dist/cache-common.cjs.js:43:27)
14:30:24
at client.search (/usr/src/app/node_modules/react-instantsearch-core/dist/cjs/core/createInstantSearchManager.js:344:50)
14:30:24
at /usr/src/app/node_modules/react-instantsearch-core/dist/cjs/core/createInstantSearchManager.js:348:29
14:30:24
at Object.get (/usr/src/app/node_modules/@algolia/cache-common/dist/cache-common.cjs.js:43:27)
14:30:24
at client.search (/usr/src/app/node_modules/react-instantsearch-core/dist/cjs/core/createInstantSearchManager.js:344:50)
14:30:24
at /usr/src/app/node_modules/react-instantsearch-core/dist/cjs/core/createInstantSearchManager.js:348:29
14:30:24
at Object.get (/usr/src/app/node_modules/@algolia/cache-common/dist/cache-common.cjs.js:43:27)
14:30:24
at client.search (/usr/src/app/node_modules/react-instantsearch-core/dist/cjs/core/createInstantSearchManager.js:344:50)
14:30:24
at /usr/src/app/node_modules/react-instantsearch-core/dist/cjs/core/createInstantSearchManager.js:348:29
14:30:24
at Object.get (/usr/src/app/node_modules/@algolia/cache-common/dist/cache-common.cjs.js:43:27)
14:30:24
at client.search (/usr/src/app/node_modules/react-instantsearch-core/dist/cjs/core/createInstantSearchManager.js:344:50)
14:30:24
at /usr/src/app/node_modules/react-instantsearch-core/dist/cjs/core/createInstantSearchManager.js:348:29
14:30:24
at Object.get (/usr/src/app/node_modules/@algolia/cache-common/dist/cache-common.cjs.js:43:27)
14:30:24
at client.search (/usr/src/app/node_modules/react-instantsearch-core/dist/cjs/core/createInstantSearchManager.js:344:50)
14:30:24
at /usr/src/app/node_modules/react-instantsearch-core/dist/cjs/core/createInstantSearchManager.js:348:29
14:30:24
at Object.get (/usr/src/app/node_modules/@algolia/cache-common/dist/cache-common.cjs.js:43:27)
14:30:24
at client.search (/usr/src/app/node_modules/react-instantsearch-core/dist/cjs/core/createInstantSearchManager.js:344:50)
14:30:24
at /usr/src/app/node_modules/react-instantsearch-core/dist/cjs/core/createInstantSearchManager.js:348:29
14:30:24
at Object.get (/usr/src/app/node_modules/@algolia/cache-common/dist/cache-common.cjs.js:43:27)
14:30:24
at client.search (/usr/src/app/node_modules/react-instantsearch-core/dist/cjs/core/createInstantSearchManager.js:344:50)
14:30:24
at /usr/src/app/node_modules/react-instantsearch-core/dist/cjs/core/createInstantSearchManager.js:348:29
14:30:24
at Object.get (/usr/src/app/node_modules/@algolia/cache-common/dist/cache-common.cjs.js:43:27)
14:30:24
at client.search (/usr/src/app/node_modules/react-instantsearch-core/dist/cjs/core/createInstantSearchManager.js:344:50)
14:30:24
at /usr/src/app/node_modules/react-instantsearch-core/dist/cjs/core/createInstantSearchManager.js:348:29
14:30:24
at Object.get (/usr/src/app/node_modules/@algolia/cache-common/dist/cache-common.cjs.js:43:27)
14:30:24
at client.search (/usr/src/app/node_modules/react-instantsearch-core/dist/cjs/core/createInstantSearchManager.js:344:50)
14:30:24
at /usr/src/app/node_modules/react-instantsearch-core/dist/cjs/core/createInstantSearchManager.js:348:29
14:30:24
at Object.get (/usr/src/app/node_modules/@algolia/cache-common/dist/cache-common.cjs.js:43:27)
14:30:24
at client.search (/usr/src/app/node_modules/react-instantsearch-core/dist/cjs/core/createInstantSearchManager.js:344:50)
14:30:24
at /usr/src/app/node_modules/react-instantsearch-core/dist/cjs/core/createInstantSearchManager.js:348:29
14:30:24
at Object.get (/usr/src/app/node_modules/@algolia/cache-common/dist/cache-common.cjs.js:43:27)

YoannDelpierre avatar Apr 07 '20 08:04 YoannDelpierre

Please make a reproducible example @YoannDelpierre, we have a template available for that purpose here. Thanks!

Haroenv avatar Apr 07 '20 08:04 Haroenv

Infortunately I can't, because it will expose my data.

{"log":"RangeError: Maximum call stack size exceeded\n","stream":"stderr","time":"2020-04-07T08:45:49.092543019Z"}
{"log":"    at String.replace (\u003canonymous\u003e)\n","stream":"stderr","time":"2020-04-07T08:45:49.092568066Z"}
{"log":"    at encode (/usr/src/app/node_modules/@algolia/transporter/dist/transporter.cjs.js:369:19)\n","stream":"stderr","time":"2020-04-07T08:45:49.09257121Z"}
{"log":"    at /usr/src/app/node_modules/@algolia/transporter/dist/transporter.cjs.js:385:21\n","stream":"stderr","time":"2020-04-07T08:45:49.092573699Z"}
{"log":"    at Array.map (\u003canonymous\u003e)\n","stream":"stderr","time":"2020-04-07T08:45:49.092576049Z"}
{"log":"    at Object.serializeQueryParameters (/usr/src/app/node_modules/@algolia/transporter/dist/transporter.cjs.js:385:10)\n","stream":"stderr","time":"2020-04-07T08:45:49.092578296Z"}
{"log":"    at /usr/src/app/node_modules/@algolia/client-search/dist/client-search.cjs.js:399:37\n","stream":"stderr","time":"2020-04-07T08:45:49.092580601Z"}
{"log":"    at Array.map (\u003canonymous\u003e)\n","stream":"stderr","time":"2020-04-07T08:45:49.092582675Z"}
{"log":"    at /usr/src/app/node_modules/@algolia/client-search/dist/client-search.cjs.js:396:34\n","stream":"stderr","time":"2020-04-07T08:45:49.092594457Z"}
{"log":"    at /usr/src/app/node_modules/react-instantsearch-core/dist/cjs/core/createInstantSearchManager.js:348:29\n","stream":"stderr","time":"2020-04-07T08:45:49.092596711Z"}
{"log":"    at Object.get (/usr/src/app/node_modules/@algolia/cache-common/dist/cache-common.cjs.js:43:27)\n","stream":"stderr","time":"2020-04-07T08:45:49.09259898Z"}

It seems I have an error on serialize my query parameters :(

YoannDelpierre avatar Apr 07 '20 09:04 YoannDelpierre

You can remove the appId & apiKey and use the credentials in the example I sent you @YoannDelpierre

Haroenv avatar Apr 07 '20 11:04 Haroenv

Problem is that it's coming after lots of requests. We reproduce the problem on a sandbox by spamming it. After 4k requests, we got the 500 and the log associated above.

YoannDelpierre avatar Apr 07 '20 12:04 YoannDelpierre

could you make clear and easy to reproduce instructions for that please? It seems quite related to your particular setup

Haroenv avatar Apr 07 '20 13:04 Haroenv

glad you found your solution @YoannDelpierre, can you explain what was the issue?

Haroenv avatar Apr 10 '20 11:04 Haroenv

hey @Haroenv , I'm using

    responsesCache: createInMemoryCache(),
    requestsCache: createInMemoryCache({ serializable: false })

Looks like the serializer does not like some requests 🤷‍♂️

YoannDelpierre avatar Apr 10 '20 12:04 YoannDelpierre

Very weird, I'd still love it if you could create a minimal reproduction for this. Cc @nunomaduro

Haroenv avatar Apr 10 '20 13:04 Haroenv

Hi @Haroenv, I finally got again the same problem as before.

It appears only after few days on production. One "better" thing today that it was the problem appears only on results when page parameters was out of range result

I can try to make a codesandbox, but we will have not the same env as we have in production (aws environment).

https://codesandbox.io/s/hidden-snowflake-8vflp my searchState based on configure object seems not working on my codesandbox 🤦 I should have 14 results and I got all of them.

YoannDelpierre avatar Apr 14 '20 08:04 YoannDelpierre

I am experiencing the exact same issue after getting many requests on the production site. I've had no issues while running in dev.

It is, as YoannDelpierre says, difficult to create a reproduction sandbox as it seems to happen when there are a lot of requests.

@Haroenv Has the official examples with next.js been load tested?

@YoannDelpierre Did you find a solution for this?

kjetilhau avatar May 08 '20 07:05 kjetilhau

@kjetilhau No I did not find a solution.. For now, I'm lucky, I deploy every day so my cache is cleaned. I think I got the problem around 10k requests.

One idea was to clear cache on SSR side, https://www.algolia.com/doc/api-client/getting-started/upgrade-guides/javascript/#the-clearcache-method

I think you're right, the official example has not been load tested.

@Haroenv can you check with your team to load test your next js example ? 🙏

YoannDelpierre avatar May 08 '20 13:05 YoannDelpierre

Tried using the null cache but still getting Maximum call stack size exceeded with only light traffic.

const searchClient = algoliasearch(	
    "xxx",	
    "xxx",	
    {	
        requestsCache: createNullCache(),	
        responsesCache: createNullCache()	
    }	
);

stuart-williams avatar May 12 '20 10:05 stuart-williams

@stuart-williams are you using next.js too ?

YoannDelpierre avatar May 13 '20 12:05 YoannDelpierre

@stuart-williams are you using next.js too ?

Yes we are using next.js

stuart-williams avatar May 13 '20 12:05 stuart-williams

@Haroenv @nunomaduro if you have free time for trying to test load your nextjs app 🙏

YoannDelpierre avatar May 13 '20 12:05 YoannDelpierre

I am off today. I will dive into this next Friday. @Haroenv Meanwhile maybe you can jump? Otherwise only Friday I will have time.

nunomaduro avatar May 13 '20 12:05 nunomaduro

I've looked into this before, but wasn't able to reproduce it. Is there a step-by-step to clone and some way to efficiently load-test it?

Haroenv avatar May 13 '20 14:05 Haroenv

We load test with Locust, python tool, on our side. We host our next.js app on AWS fargate.

YoannDelpierre avatar May 13 '20 14:05 YoannDelpierre

We test directly on your nextjs example with locust

image

We send around 1700 requests.

Do you have more detail on your side by reading logs ?

YoannDelpierre avatar May 13 '20 14:05 YoannDelpierre

Going to tackle this. Gonna get back to you guys once I find the problem.

nunomaduro avatar May 14 '20 14:05 nunomaduro