next.js: Error: Failed to find Server Action "84c...c2". This request might be from an older or newer deployment. Original error: Cannot read properties of undefined (reading 'workers')
Link to the code that reproduces this issue
https://github.com/72L/failed-to-find-server-action
To Reproduce
- Deploy repro repo to Heroku app:
heroku git:remote -a [your-app]andgit push heroku main - Test that it works and keep this tab open (do not refresh)
- Make an insignificant change (i.e. modify the readme or add a space)
- deploy to heroku again
git push heroku main - Do not refresh tab from step 2!
- After successful deploy, test the app. The server action is now unresponsive.
- Look into logs and see something like this:
2024-09-18T19:54:44.246958+00:00 app[web.1]: Error: Failed to find Server Action "84c3beb04922e6ef5f718f755f306f3e442d01c2". This request might be from an older or newer deployment. Original error: Cannot read properties of undefined (reading 'workers')
2024-09-18T19:54:44.246972+00:00 app[web.1]: at r$ (/app/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:16:1766)
2024-09-18T19:54:44.246972+00:00 app[web.1]: at /app/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:15:8948
2024-09-18T19:54:44.246972+00:00 app[web.1]: at AsyncLocalStorage.run (node:async_hooks:346:14)
2024-09-18T19:54:44.246973+00:00 app[web.1]: at rT (/app/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:15:8156)
2024-09-18T19:54:44.246973+00:00 app[web.1]: at ne (/app/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:18:1150)
2024-09-18T19:54:44.246973+00:00 app[web.1]: at /app/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:19:726
2024-09-18T19:54:44.246973+00:00 app[web.1]: at AsyncLocalStorage.run (node:async_hooks:346:14)
2024-09-18T19:54:44.246974+00:00 app[web.1]: at Object.wrap (/app/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:13:17831)
2024-09-18T19:54:44.246975+00:00 app[web.1]: at /app/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:19:616
2024-09-18T19:54:44.246975+00:00 app[web.1]: at AsyncLocalStorage.run (node:async_hooks:346:14)
Current vs. Expected behavior
I would expect the outcome of step 2 to be the same as the outcome of step 6.
Provide environment information
Operating System:
Platform: darwin
Arch: arm64
Version: Darwin Kernel Version 23.4.0: Fri Mar 15 00:12:41 PDT 2024; root:xnu-10063.101.17~1/RELEASE_ARM64_T8103
Available memory (MB): 16384
Available CPU cores: 8
Binaries:
Node: 18.20.2
npm: 10.5.0
Yarn: 1.22.19
pnpm: 6.29.0
Relevant Packages:
next: 14.2.12 // Latest available version is detected (14.2.12).
eslint-config-next: 14.2.12
react: 18.3.1
react-dom: 18.3.1
typescript: 5.6.2
Next.js Config:
output: N/A
Which area(s) are affected? (Select all that apply)
Not sure
Which stage(s) are affected? (Select all that apply)
Other (Deployed)
Additional context
It does work on Vercel, but not Heroku. I’ve tried some ideas from https://github.com/vercel/next.js/discussions/58431 but none of them solved this issue.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 4
- Comments: 20 (6 by maintainers)
I’ve been able to reproduce this issue as well. It seems like new server action IDs are always generated when there is no build cache. You can verify it locally:
next build.next startand open the page. Leave the page open..next.Especially with self-hosting this is problematic because the more frequently you deploy new releases the more likely your users will have trouble with server actions.
Probably we could cache the
.nextdirectory between builds because this seems to preserve server action IDs. But I’m not sure if there is an expiry time since the documentation mentions that IDs “are cached for a maximum of 14 days”. See https://nextjs.org/docs/app/building-your-application/data-fetching/server-actions-and-mutations#securityIn my opinion, there should be a configuration to opt-out of this ID rotation. Something like this:
With the option set to
falseserver action IDs should not change between builds, even when cleaning up the build cache. Server actions should then rather behave like “auto-generated API route handlers”.I DO have issue with vercel deployment in every canary version since at least 171.
however, it’s hard to reproduce since it seems to be related to long-time use cases.
For now, I’ve opted out of server actions in this use case, and I couldn’t find workaround.
Not sure how reproduction can be provided, since it takes hours and production setup to actually have that.
We have 1000+ users and only a subset get this error, but a substantial subset: dozens of issues per day.
Isn’t that something that might be very important? I mean, if server actions security mechanism is not stable in long-running sessions (and there are lots of cases when apps are constantly open without reloading for days), that is important, no?
As I said before, enabling skew protection and setting encryption key did not have effect.
I am ready to collaborate on experiments, and even test out in production with our users and give access to our logs and so on.