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

Error: Failed to set Next.js data cache #836

Closed
davidmytton opened this issue May 28, 2024 · 4 comments · Fixed by #838
Closed

Error: Failed to set Next.js data cache #836

davidmytton opened this issue May 28, 2024 · 4 comments · Fixed by #838
Assignees

Comments

@davidmytton
Copy link
Contributor

I have seen one instance of this error with Next.js and had a report from a user about it as well, but I can't reproduce. It logs a huge base64 encoded string and then errors:

...
Q0AAGFhAAACAAAABQAAAAAAAAD+DQAAbm4AAAIAAAAFAAAAAAAAAP8NAABpaQAAAgAAAAUAAAAAAAAAJQ4AAGVlAAACAAAABQAAAAAAAAABDgAAc3MAAAIAAAAFAAAAAAAAAAIOAAB1dQAAAgAAAAUAAAAAAAAAAw4AAHBwAAACAAAABQAAAAAAAAAEDgAAZWUAAAIAAAAFAAAAAAAAAAUOAABycgAAAgAAAAUAAAAAAAAABg4AAGZmAAACAAAABQAAAAAAAAAHDgAAZWUAAAIAAAAFAAAAAAAAAAgOAABlZQAAAgAAAAUAAAAAAAAACQ4AAGRkAAACAAAABQAAAAAAAAAlDgAAcnIAAAIAAAAFAAAAAAAAAAsOAAB3dwAAAgAAAAUAAAAAAAAADA4AADMzAAACAAAABQAAAAAAAAANDgAAY2MAAAIAAAAFAAAAAAAAAA4OAABfXwAAAgAAAAUAAAAAAAAADw4AAHV1AAACAAAABQAAAAAAAAAQDgAAbm4AAAIAAAAFAAAAAAAAABEOAABpaQAAAgAAAAUAAAAAAAAAEg4AAGNjAAACAAAABQAAAAAAAAATDgAAb28AAAIAAAAFAAAAAAAAABQOAABycgAAAgAAAAUAAAAAAAAAJQ4AAG5uAAACAAAABQAAAAAAAAAWDgAAZGQAAAIAAAAFAAAAAAAAABcOAABvbwAAAgAAAAUAAAAAAAAAGA4AAG1tAAACAAAABQAAAAAAAAAZDgAAYWEAAAIAAAAFAAAAAAAAABoOAABpaQAAAgAAAAUAAAAAAAAAGw4AAG5uAAACAAAABQAAAAAAAAAcDgAAc3MAAAIAAAAFAAAAAAAAAB0OAAAgIAAAAgAAAAUAAAAAAAAAHg4AAHBwAAACAAAABQAAAAAAAAAfDgAAcnIAAAIAAAAFAAAAAAAAACAOAABvbwAAAgAAAAUAAAAAAAAAIQ4AAGpqAAACAAAABQAAAAAAAAAiDgAAZWUAAAIAAAAFAAAAAAAAACMOAABjYwAAAgAAAAUAAAAAAAAAJA4AAHR0AAACAAAABQAAAAAAAAAlDgAALy8AAAIAAAAFAAAABgAAACYOAEGMlYMBCwUBAAAACABBoJWDAQsBAQBBnN+DAQsDQRABAEHc/4cBCwEoAEcJcHJvZHVjZXJzAQxwcm9jZXNzZWQtYnkCDXdpdC1jb21wb25lbnQHMC4yMDEuMBB3aXQtYmluZGdlbi1ydXN0BjAuMjIuMA== Error: Failed to set Next.js data cache, items over 2MB can not be cached (4498890 bytes)
example-next:dev:     at IncrementalCache.set (/app/node_modules/next/dist/server/lib/incremental-cache/index.js:391:23)
example-next:dev:     at /app/node_modules/next/dist/compiled/next-server/app-route.runtime.dev.js:6:51077
example-next:dev:     at async wasm (webpack-internal:///(rsc)/../../node_modules/@arcjet/analyze/_virtual/arcjet_analyze_js_req.component.core.js:39:22)
example-next:dev:     at async moduleFromPath (webpack-internal:///(rsc)/../../node_modules/@arcjet/analyze/index.js:23:25)
example-next:dev:     at async Promise.all (index 0)
example-next:dev: ✦Aj [analyze wasm] generate_fingerprint input: 192.168.247.0
example-next:dev: ✦Aj [analyze wasm] Struct = Fingerprint { prefix: "fp", version: 1, ip: 192.168.247.0 }
example-next:dev: ✦Aj [analyze wasm] String = 192.168.247.0
example-next:dev: ✦Aj fingerprint (node): fp_1_918a34e3c2a0124ba9d2f7ba2d862b60e6f6bff2d4a428e8b99b6235aa0d0d26
example-next:dev: ✦Aj Latency fingerprint: 209.831ms
example-next:dev: ✦Aj Latency cache: 0.027ms
example-next:dev: ✦Aj Latency local: 209.96ms
example-next:dev: ✦Aj Decide request to https://decide.arcjet.orb.local:4082
example-next:dev: ✦Aj Decide response {
example-next:dev:   id: 'req_01hyz6j5qheqq8x3331962r1pk',
example-next:dev:   fingerprint: 'fp_1_918a34e3c2a0124ba9d2f7ba2d862b60e6f6bff2d4a428e8b99b6235aa0d0d26',
example-next:dev:   path: '/api_app/protect_api',
example-next:dev:   runtime: 'node',
example-next:dev:   ttl: 0,
example-next:dev:   conclusion: 'ALLOW',
example-next:dev:   reason: ArcjetShieldReason { type: 'SHIELD', shieldTriggered: false },
example-next:dev:   ruleResults: [
example-next:dev:     ArcjetRuleResult {
example-next:dev:       ruleId: '',
example-next:dev:       ttl: 0,
example-next:dev:       state: 'RUN',
example-next:dev:       conclusion: 'ALLOW',
example-next:dev:       reason: [ArcjetShieldReason]
example-next:dev:     }
example-next:dev:   ]
example-next:dev: }
example-next:dev: ✦Aj Latency decideApi: 18.351ms
example-next:dev: ✦Aj Latency remote: 18.391ms
example-next:dev:  GET /api_app/protect_api 200 in 894ms
@blaine-arcjet
Copy link
Contributor

This looks like the base64 of one of our wasm files. We use fetch to decode, which I believe Next passes through the vercel cache by default. We probably need to add some cache: false setting to skip it.

@davidmytton
Copy link
Contributor Author

For Next.js this can be controlled by setting { cache: 'no-store' } on fetch (which will be the default from Next.js 15).

@blaine-arcjet blaine-arcjet self-assigned this May 28, 2024
@davidmytton
Copy link
Contributor Author

I was able to reproduce on the Next.js app router with one of our test routes: https://example-next.arcjet.orb.local/api_app/protect_api_rl. It doesn't reproduce with the pages router. Adding const dynamic = 'force-dynamic' fixes the issue because it opts the route out of caching.

@blaine-arcjet
Copy link
Contributor

I followed the reproduction and added { cache: 'no-store' } to the fetch and it no longer errors. I'll get a patch submitted shortly.

@trunk-io trunk-io bot closed this as completed in #838 May 29, 2024
trunk-io bot pushed a commit that referenced this issue May 29, 2024
Closes #836 

We are using `fetch` to base64 decode our Analyze Wasm files in certain runtimes. However, when this is used in the Next.js App Router, it fails because the URL is larger than 2mb. We don't actually need these to go through the `fetch` cache since it isn't making a network call, so we just disable it everywhere.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants