Back

Cron based Function errors with error code: 524

  • 0
  • Functions
  • Cloud
Marcel
3 Mar, 2025, 15:17

The function timeout is set to 900 seconds, but the function gives a 524 error after 1 minute (according to the dashboard UI). It is a cron scheduled function. I can't see the logs because it errors, so I don't even know how far it gets.

TL;DR
Developers facing error code 524 in a cron function despite setting a 900-second timeout. Issue likely due to slow queries, crashing with no error logs past 50 iterations. Increasing limit, adding a select query, and reducing payload suggested solutions. Manually testing function execution recommended to identify problems.
Kenny
3 Mar, 2025, 15:22

AFAIK 524 is a timeout error. What does the function do? If you call it directly does it work?

Marcel
3 Mar, 2025, 15:23

The counts the number of users in the db with the users endpoint. It has to do some cursor pagination because there are more than 5k

Marcel
3 Mar, 2025, 15:24

it gets triggered internally by the schedule cron

Kenny
3 Mar, 2025, 15:24

Sure, but can you execute it manually, and does it fail then too?

Marcel
3 Mar, 2025, 15:24

you mean manually using the appwrite dashboard UI?

Kenny
3 Mar, 2025, 15:24

Yes

Marcel
3 Mar, 2025, 15:25

it's now running

Marcel
3 Mar, 2025, 15:26

failed again:

Kenny
3 Mar, 2025, 15:27

Could you up the timeout period?

Marcel
3 Mar, 2025, 15:27

it is set to 900

Kenny
3 Mar, 2025, 15:30

Could you provide the function code?

Marcel
3 Mar, 2025, 15:33

i'm setting a counter to see if it exactly crashes after 60 sec.. i just ran it with less max pages and it run in 34 seconds normally.

Kenny
3 Mar, 2025, 15:37

So if you lower the amount you're fetching it works?

Kenny
3 Mar, 2025, 15:37

Maybe try increasing the limit so it has fewer http requests, and add a select query and select only the $id, so it reduces the payload.

Marcel
3 Mar, 2025, 15:42
TypeScript
    log(`fetching page ${counter++}`)
    const query = lastId ? [Query.limit(limit), Query.cursorAfter(lastId)] : [Query.limit(limit)]
    const page = await users.list(query)
    allUsers = allUsers.concat(page.users)
    lastId = page.users.length > 0 ? page.users[page.users.length - 1].$id : undefined
  } while (lastId && counter < 50)```

it actually runs past 1 minute if I increase the counter enough, so it doesn't seem like a timeout issue. But when I remove the counter it crashes with this vague error code: 524 and then it doesn't display any logs so it's a bit hard to debug the issue. Maybe it's something with the lastId check.
Marcel
3 Mar, 2025, 15:42

ow with 50 it actually crashes

Kenny
3 Mar, 2025, 15:43

It seems like it's an issue with slow queries, but I agree it is hard to know exactly what the issue is

Marcel
3 Mar, 2025, 15:43

anyway to see the actual output / error logs?

Marcel
3 Mar, 2025, 15:43

stacktraces?

Kenny
3 Mar, 2025, 15:45

Are you on cloud?

Marcel
3 Mar, 2025, 15:46

Yep

Marcel
3 Mar, 2025, 15:47

PS. the Query.select you suggested to select only the $id doesn't seem to work on the users.list method AppwriteException: Invalid queries` param: Invalid query method: select

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more