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 find Server Action "84c...c2". This request might be from an older or newer deployment. Original error: Cannot read properties of undefined (reading 'workers') #70229

Open
72L opened this issue Sep 18, 2024 · 16 comments
Labels
bug Issue was opened via the bug report template. linear: next Confirmed issue that is tracked by the Next.js team.

Comments

@72L
Copy link

72L commented Sep 18, 2024

Link to the code that reproduces this issue

https://github.com/72L/failed-to-find-server-action

To Reproduce

  1. Deploy repro repo to Heroku app: heroku git:remote -a [your-app] and git push heroku main
  2. Test that it works and keep this tab open (do not refresh)
  3. Make an insignificant change (i.e. modify the readme or add a space)
  4. deploy to heroku again git push heroku main
  5. Do not refresh tab from step 2!
  6. After successful deploy, test the app. The server action is now unresponsive.
  7. 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 #58431 but none of them solved this issue.

@72L 72L added the bug Issue was opened via the bug report template. label Sep 18, 2024
@samcx samcx added the linear: next Confirmed issue that is tracked by the Next.js team. label Sep 24, 2024
@samcx
Copy link
Member

samcx commented Sep 24, 2024

@72L Thank you for submitting an issue!

Will be flagging this to the team again to take a look.

@tpudel
Copy link

tpudel commented Oct 2, 2024

Currently running into the same issue, tried a few things but still occurs periodically in our self hosted docker nextjs server on ec2 with kubernetes.

@neoromantic
Copy link

same issue. hosting on vercel.

my users often have app opened for a long time in browser. after deploys they get this error and it is super inconvenient.

running next-15-rc2.

@neoromantic
Copy link

here's an example. I really am baffled on what to do now...

Error: Failed to find Server Action "81687d1e7f3efe93bb72224da749701d6348fad2". This request might be from an older or newer deployment. Original error: Cannot read properties of undefined (reading 'workers')
    at rd (/var/task/node_modules/next/dist/compiled/next-server/app-page-experimental.runtime.prod.js:127:2692)
    at /var/task/node_modules/next/dist/compiled/next-server/app-page-experimental.runtime.prod.js:127:757
    at AsyncLocalStorage.run (node:async_hooks:346:14)
    at rc (/var/task/node_modules/next/dist/compiled/next-server/app-page-experimental.runtime.prod.js:126:11732)
    at n6 (/var/task/node_modules/next/dist/compiled/next-server/app-page-experimental.runtime.prod.js:132:1243)
    at /var/task/node_modules/next/dist/compiled/next-server/app-page-experimental.runtime.prod.js:132:6400
    at AsyncLocalStorage.run (node:async_hooks:346:14)
    at th (/var/task/node_modules/next/dist/compiled/next-server/app-page-experimental.runtime.prod.js:124:87847)
    at /var/task/node_modules/next/dist/compiled/next-server/app-page-experimental.runtime.prod.js:132:6250
    at AsyncLocalStorage.run (node:async_hooks:346:14)

@72L
Copy link
Author

72L commented Oct 18, 2024

For the moment, I am no longer using server actions. I'm just using fetch on client side to api route handlers.

@neoromantic
Copy link

Can it be related to https://nextjs.org/blog/next-15-rc2#enhanced-security-for-server-actions ?

Secure action IDs: Next.js now creates unguessable, non-deterministic IDs to allow the client to reference and call the Server Action. These IDs are periodically recalculated between builds for enhanced security.

I started having problems after I updated to some canary version.

I also found this: https://nextjs.org/blog/security-nextjs-server-components-actions#closures

In Next.js 14, the closed over variables are encrypted with the action ID before sent to the client. By default a private key is generated automatically during the build of a Next.js project. Each rebuild generates a new private key which means that each Server Action can only be invoked for a specific build. You might want to use Skew Protection to ensure that you always invoke the correction version during redeploys.

If you need a key that rotates more frequently or is persistent across multiple builds, you can configure it manually using NEXT_SERVER_ACTIONS_ENCRYPTION_KEY environment variable.

So I guess if I set NEXT_SERVER_ACTIONS_ENCRYPTION_KEY to something stable, it might help

@neoromantic
Copy link

@neoromantic
Copy link

I've added Encryption_key and enabled skew protection, but still get these errors (on most important route!):

Error: Failed to find Server Action "b89530f2bea0761ce728f279ca62a5d5c93394c5". This request might be from an older or newer deployment. Original error: Cannot read properties of undefined (reading 'workers')```

@neoromantic
Copy link

For now, I moved away from using server action in this particular case, which is a bummer.

Since for me it is a recording of long-form audio in browser, I cannot afford to lose it due to "cannot find server action". And it happened all the time.

I've tried various things, but my expertise are not enough to figure it out. Really waiting for someone from the team to maybe point in right direction.

@neoromantic
Copy link

@huozhi sorry for ping, but maybe you can shed a little light?

@huozhi
Copy link
Member

huozhi commented Oct 24, 2024

Verified the reproduction is working well in local and deployment on vercel, if it's not working on heroku it's likely a platform issue that not owned by Next.js.

If you're seeing any issue with vercel deployment, please file a new issue with reproduction, thanks

@huozhi huozhi closed this as completed Oct 24, 2024
@neoromantic
Copy link

Verified the reproduction is working well in local and deployment on vercel, if it's not working on heroku it's likely a platform issue that not owned by Next.js.

If you're seeing any issue with vercel deployment, please file a new issue with reproduction, thanks

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.

  • User opened a website
  • User went to a page with long-running (in my case audio recording) actions, that might be active for few hours
  • I might have new deployments during that time, and it seems that problem arise because of new deployments
  • I get log errors just as provided in this task

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.

@neoromantic
Copy link

We have similar reports here: #69756 (comment), talking about canary builds of 15.0.0, and only in prod.

I had this error on 15.0.1 stable as well.

Sadly, it business-critical and we cannot allow to continue experiments on our users. But I really would like to be able to make sure everything works.

@controversial
Copy link
Contributor

controversial commented Nov 4, 2024

I’m also becoming worried that version skew is causing “server action not found” errors in production because of the recently introduced “randomized/unguessable” server action IDs

it seems like creating new deployments is causing an uptick in users encountering this issue, which leads me to believe that maybe the IDs changing between builds are to blame, as users who loaded a previous deployment can no longer access server actions after a new deployment, because all of the action IDs have changed

Under the “old” model where we created API routes with explicit names, this was never the case

@samcx samcx reopened this Nov 5, 2024
@timarney
Copy link

timarney commented Nov 7, 2024

I’m also becoming worried that version skew is causing “server action not found” errors in production because of the recently introduced “randomized/unguessable” server action IDs

Running into the same issue.

Happening between deployments (self hosted).

Is there a way to use "Next 14 style" server Ids in Next 15?

@georgwittberger
Copy link

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:

  1. Create a production build using next build.
  2. Start the app using next start and open the page. Leave the page open.
  3. Terminate the app and delete the directory .next.
  4. Create another production build.
  5. Start the app again.
  6. Go to the page again (do not reload!) and just execute the server action.

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 .next directory 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#security

In my opinion, there should be a configuration to opt-out of this ID rotation. Something like this:

/** @type {import('next').NextConfig} */

module.exports = {
  experimental: {
    serverActions: {
      encryptedActionIds: false, // default: true
    },
  },
}

With the option set to false server 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".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue was opened via the bug report template. linear: next Confirmed issue that is tracked by the Next.js team.
Projects
None yet
Development

No branches or pull requests

8 participants