Cloudflare Worker exceeded CPU time limit, while sign-up/email.

I was trying better-auth on cloudfare with hono and D1, and while I have a free plan on cloudflare that allows for up to 10ms CPU time per request, I am receiving Worker exceeded CPU time limit errors. This occurs during sign-up/email; I understand that sign-up involves multiple processes, including hono zod validation, among others. My concern is, do I need to upgrade my plan to get this working, or can I optimize my code or something? For example, I was thinking about using drizzleAdapter for authentication; could I change it to Kysely, or idk.
No description
Solution:
It's very likely you will need to upgrade. In certain endpoints, such as sign up email, we will do multiple adapter calls to your DB, 1 call alone is most likely more than 10 ms alone, let alone maybe 3 calls....
Jump to solution
13 Replies
Solution
Ping
Ping5mo ago
It's very likely you will need to upgrade. In certain endpoints, such as sign up email, we will do multiple adapter calls to your DB, 1 call alone is most likely more than 10 ms alone, let alone maybe 3 calls.
Abdi
AbdiOP5mo ago
I see. So, the Cloudflare free plan is not really free.
stu
stu5mo ago
@Abdi @Ping I have a Cloudflare business plan, and still encounter this issue. For reference regarding CPU limits in workers: https://developers.cloudflare.com/workers/platform/limits/#cpu-time No idea why Better-Auth would be hitting these limits, they're generous enough for basic stuff like a DB query to gather user info.
Cloudflare Docs
Limits · Cloudflare Workers docs
Cloudflare Workers plan and platform limits.
DeepSeek R2
DeepSeek R25mo ago
I think this is some bug.
DeepSeek R2
DeepSeek R25mo ago
in my case: there is issue with CORS cause cpu limit. after fix it, it work normal. No need to upgrade to paid plan.
No description
DeepSeek R2
DeepSeek R25mo ago
No description
stu
stu5mo ago
Thanks for the response, I'll give this a try. Just to clarify, where are you putting the origin param? When initializing betterAuth, I see a trustedOrigins param? Are you referring to that?
DeepSeek R2
DeepSeek R25mo ago
I used Better in my Hono Backend.
No description
DeepSeek R2
DeepSeek R25mo ago
There are bug with cors, When i do exact this, it work. If i change to it will get error.
...
origin [c.env.CORS_ORIGIN, "localhost:3000", "localhost:8787"] // Won't work.
...
origin [c.env.CORS_ORIGIN, "localhost:3000", "localhost:8787"] // Won't work.
So I think we should set fixed value for cors trusted.
Abdi
AbdiOP4mo ago
I now upgraded to paid plan and it works now, there is no issues for me i don't think it's cors issue although i will try this
Abdi
AbdiOP4mo ago
speaking of cors this is my cors config now
No description
No description
DeepSeek R2
DeepSeek R24mo ago
yes, in my case env.cors is undefine, so it break in some case.
stu
stu4mo ago
Good to know. I'm on a paid plan, and still getting errors for email/pass signin. It's really odd behavior. It throws a timeout the first time I try to sign in, then works the second time. But it's really slow. I'm using just a normal Postgres DB, might try and migrate the user auth parts to D1.

Did you find this page helpful?