(Cloudflare) Workers CPU resources exceeded

Hello everyone, I have a web app made using SvelteKit and am facing this issue where my cpu resources are being exceeded while signing in or up, i.e the limit of 10ms CPU time is not enough for these auth purposes, now is there any way to avoid this or only upgrading to paid plans can make it avoid this problem? I have two alternatives or workaround I can use: - Create a different server for this sole purpose, i.e a deno server which signs in, parses the cookie sends back to our main app - Migrate to something like Vercel. Is the first solution viable and vulnerable to security concerns? Currently this is the code am using:

default: async ({ request, cookies }) => {
let body = await request.formData()
let email = body.get('email') as string
let password = body.get('password') as string

try {
let res = await auth.api.signInEmail({
body: {
email,
password
},
asResponse: true
});


const setCookieHeader = res.headers.get('set-cookie');

if (setCookieHeader) {
const valueIndex = setCookieHeader.indexOf('=');
const semicolonIndex = setCookieHeader.indexOf(';');
const encodedValue = setCookieHeader.slice(
valueIndex + 1,
semicolonIndex > -1 ? semicolonIndex : undefined
);
const decodedValue = decodeURIComponent(encodedValue);

cookies.set('better-auth.session_token', decodedValue, {
path: '/',
httpOnly: true,
maxAge: 604800,
sameSite: 'lax'
});
} else {
return fail(500, { internalServerError: "Something went wrong while signing in" })
}
}catch(){
//other code
}
}

default: async ({ request, cookies }) => {
let body = await request.formData()
let email = body.get('email') as string
let password = body.get('password') as string

try {
let res = await auth.api.signInEmail({
body: {
email,
password
},
asResponse: true
});


const setCookieHeader = res.headers.get('set-cookie');

if (setCookieHeader) {
const valueIndex = setCookieHeader.indexOf('=');
const semicolonIndex = setCookieHeader.indexOf(';');
const encodedValue = setCookieHeader.slice(
valueIndex + 1,
semicolonIndex > -1 ? semicolonIndex : undefined
);
const decodedValue = decodeURIComponent(encodedValue);

cookies.set('better-auth.session_token', decodedValue, {
path: '/',
httpOnly: true,
maxAge: 604800,
sameSite: 'lax'
});
} else {
return fail(500, { internalServerError: "Something went wrong while signing in" })
}
}catch(){
//other code
}
}
Help would be really appreciated, Thanks.
5 Replies
SheldonFromBBT
SheldonFromBBTOP3mo ago
Even using client auth doesnt solve this issue. This happens only while signing in with email and password method
stu
stu3d ago
Hey @SheldonFromBBT , were you able to find a fix for this? I'm running into the same thing ATM.
SheldonFromBBT
SheldonFromBBTOP3d ago
Unfortunately no, I have migrated to using just oauth with google. I have stopped using email and password authentication because of this issue, there seems no actual fix due to its nature, upgrading to paid tier might only be the viable solution.
stu
stu3d ago
I'm actually running on a Cloudflare business account, and still get the error.
SheldonFromBBT
SheldonFromBBTOP3d ago
Then this issue shouldn't be taking place, IMO Try to use their cpu limit configuration, what I know is you can set some higher time limit for paid tiers, take a look at that Or just contact their support

Did you find this page helpful?