You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
π Bug Report: Appwrite freezes randomly on function executionΒ #4626
I have an Appwrite server on decent hardware (2 core CPU and 4 gigs of RAM).
There are many collections in my database and I use functions to retrieve and edit data before sending it to the client β functions are called very often.
I still havenβt figured out why/when exactly but at some point the server doesnβt serve functions, I can requests accumulating on the functions logs :
(this get_feed function only queries data, compacts it and send it back to the client)
At first the backend interface is still responsive but at some point other functions freeze and iβm unable to load pages or query anything.
The appwrite doctor doesnβt show any issues :
Thanks
π Expected behavior
It should not crash as the functions donβt require a lot of memory, and runs without any issues during my stress tests.
π Actual Behavior
Appwrite freezes for a while and then comes back after 15-20 minutes.
π² Appwrite version
Version 1.0.x
π» Operating system
Linux
π§± Your Environment
Only pure Appwrite is running on the server.
π Have you spent some time to check if this issue has been raised before?
@netapy thanks for raising this issue! ππΌ Would you please provide the executor logs and check docker ps -a to see if the runtime container is still running? If it is, the logs from the runtime container can be helpful too.
@netapy, docker logs <container name or id>. The container should be named <project id>-<deployment id>. Are these for when the function was frozen? What was the deployment ID for the frozen function?
Usually the one ending with 838e freezes first, but then the freeze generalizes to the whole appwrite application.
Also it recovers by itself after 15-20 minutes.
Message: An internal curl error has occurred within the executor! Error Msg: Operation timed out
check your variables for the function APPWRITE_FUNCTION_ENDPOINThttp://<domain>.com/v1 you must have forgotten v1
Message: An internal curl error has occurred within the executor! Error Msg: Operation timed out
check your variables for the function APPWRITE_FUNCTION_ENDPOINThttp://<domain>.com/v1 you must have forgotten v1
Thanks for your answer. Unfortunately I re-checked my code and it includes the right variables β my functions run correctly until some point in time (which I havenβt determined yet).
Not sure if this helps but when I docker compose down it seems that my appwrite_runtimes container has trouble shutting down. Logs below :
@netapy
Are you by any chance running a docker version installed through snapd on Ubuntu?
After lots of testing, i noticed, that the functions are far less likely to get stuck on my Docker Desktop Windows environment.
So I tested different things and finally I replaced the snapd version with the version from the official Docker repo, while copying all my volumes over and it seems much more stable now.
When spamming a simple function 10.000 times (10 parallel), it still fails between 0-50 times. But it seems that now at least it takes much more effort to pull down the whole system.
I'm running Ubuntu 22.04 LTS in a VM with 4 cores/4Gb.
Before: Docker installed via OS installer/snap (20.10.17)
Now: Docker installed using Docker repo (20.10.21)
Some other interesting things that i noticed..
I got two functions
testFunction, that creates one simple document in the DB (called 10.000 times)
monitoring function which gets health data and collection info every 30 seconds
1.) When spamming the testFunction too hard (like 20 in parallel), often it is the monitoring function that gets completely stuck, and fails to recover indefinitely, while the testFunction is still able to create Documents.
Only after waiting some minutes and starting calling the testFunction again (or occasionally even refreshing the web console) the monitoring function suddenly starts working again.
2.) Functions that don't access the appwrite API don't seem to be affected by those problems at all.
So to me it seems like the problem (at least in my case) lies somewhere between the runtime container and the appwrite API, which causes it to randomly get stuck if stressed too much.
And it recovers most of the time, but not always.
Also it can still work for one function, but not for another one.
Plus, causing another unrelated call on the API, sometimes gets everything running again.
Another thing i noticed just now:
Increasing _APP_WORKER_PER_CORE also seems to help quite a bit to get rid of this.
I set it from 6 to 12 and now i get much less failed executions, despite spamming 15 parallel executions.
Well, unfortunately it's still happening from time to time, even under less load. I'm out of ideas...
@redarflap thanks for your input.
Yes I am running my server on Ubuntu 22.04LTS, but my Docker always was from the official repository..
I have found that when I decreased the function timeout somewhere between 5-10 seconds, my server would not crash anymore, only the function(s).
I tried out the solution with the _APP_WORKER_PER_CORE but it doesn't seem to fix it, I still get random functions that don't launch, rendering the following error : An internal curl error has occurred within the executor! Error Msg: Operation timed out
On the logs of the executor container, I get the following :
Executing Runtime: 62e0fcfca3b3c5124f16-638dd2d795d639e0cacd
[Error] Type: Exception
[Error] Message: An internal curl error has occurred within the executor! Error Msg: Operation timed out
[Error] File: /usr/src/code/app/executor.php
[Error] Line: 544
Are your error logs on the Appwrite executor the same as mine ?
I also noticed that only the functions that work with the Appwrite API get this kind of error/freeze.
I tried rewriting my functions in Node JS (previously Python) but that doesn't change a thing.
Intermittent.
Appwrite version: v:0.15.2.402
Windows WSL 2
Docker Version: 4.10.1 (82475)
Server spec: 4cores 8gb rams
Function runtime: Node16
No logs from runtime container
docker compose logs appwrite-executor
Based on users above commented, looks like this is still occurring on latest version.
Upgrading my Appwrite version to latest might have minor chances being fixed.
but I'll try.
This is a function that aggregate and generate an end day report which have dozen of loops.
Noticed that after continuous 4-5 execution in a row, the function failed to perform and resulted Operation Timed Out error.
Also checked the x-ratelimit-limit = 60 & x-ratelimit-remaining = 54, nothing seems related to rate limit.
Appwrite Cloud Function is a crucial feature.
Hope someone look into this seriously.
I will deep dig the mentioned .php line error when leisure.
Edit: 4 Jan 2023
tried docker compose down && docker compose up -d
and trigger the function execution continuously 10 times + until it Timed Out, maybe redis cache issue.
@TheDarkX, I tried creating dozens of executions of:
constsdk=require("node-appwrite");functionsleep(ms){returnnewPromise((resolve)=>{setTimeout(resolve,ms);});}module.exports=asyncfunction(req,res){constclient=newsdk.Client();if(!req.variables['APPWRITE_FUNCTION_ENDPOINT']||!req.variables['APPWRITE_FUNCTION_API_KEY']){console.warn("Environment variables are not set. Function cannot use Appwrite SDK.");}else{client.setEndpoint(req.variables['APPWRITE_FUNCTION_ENDPOINT']).setProject(req.variables['APPWRITE_FUNCTION_PROJECT_ID']).setKey(req.variables['APPWRITE_FUNCTION_API_KEY']).setSelfSigned(true);}awaitsleep(200);res.json({areDevelopersAwesome: true,});};
but they all executed fine:
Is there some promise in your code that isn't resolving? Perhaps you could try adding console.stdlog() (yes, stdlog) and check the runtime container logs?
@netapy, are you still experiencing the problem after adding the try/except?
@stnguyen90
Should have came back to share it but it seems that I kind of solved my problem by setting the _APP_FUNCTIONS_INACTIVE_THRESHOLD appwrite env variable to a month or so.
The constant restart of the function apparently caused the crashes.
Not sure about it though but it seems more stable since then.
It does not look like an issue you should close to me. Is there a fix I missed ?
FYI, we had to completely switch to a docker based node backend to satisfy our client as the cloud functions were not reliable.
Tweaking _APP_FUNCTIONS_INACTIVE_THRESHOLD might be a workaround but it also has its reason to exist and to be used.
Hey @stnguyen90 , found a way to reproduce it with a clear use-cases. And, I think maybe there is a solution to overcome it.
Is there any option to reopen the issue and get it reassigned?
Activity
stnguyen90 commentedon Nov 2, 2022
@netapy thanks for raising this issue! ππΌ Would you please provide the executor logs and check
docker ps -ato see if the runtime container is still running? If it is, the logs from the runtime container can be helpful too.netapy commentedon Nov 2, 2022
Sure, as of writing this message the issue is ongoing and this is the log :
netapy commentedon Nov 2, 2022
And this is the executor log :
edit : how can I get the log from the runtime container ?
stnguyen90 commentedon Nov 2, 2022
@netapy,
docker logs <container name or id>. The container should be named<project id>-<deployment id>. Are these for when the function was frozen? What was the deployment ID for the frozen function?netapy commentedon Nov 2, 2022
Yes these logs were taken when the function was frozen.
Itβs weird my containers are able to display logs, except for the two python openruntimes containers.

stnguyen90 commentedon Nov 2, 2022
@netapy, which deployment ID is the frozen one?
netapy commentedon Nov 2, 2022
Usually the one ending with 838e freezes first, but then the freeze generalizes to the whole appwrite application.
Also it recovers by itself after 15-20 minutes.
stnguyen90 commentedon Nov 2, 2022
@netapy is this
get_feedfunction being executing asynchronously or synchronously?netapy commentedon Nov 2, 2022
βget_feedβ is launched synchronously, as are all my functions.
Shiba-Kar commentedon Nov 3, 2022
Message: An internal curl error has occurred within the executor! Error Msg: Operation timed outcheck your
variablesfor the functionAPPWRITE_FUNCTION_ENDPOINThttp://<domain>.com/v1you must have forgottenv1netapy commentedon Nov 3, 2022
Thanks for your answer. Unfortunately I re-checked my code and it includes the right variables β my functions run correctly until some point in time (which I havenβt determined yet).
Not sure if this helps but when I
docker compose downit seems that myappwrite_runtimescontainer has trouble shutting down. Logs below :Shiba-Kar commentedon Nov 3, 2022
docker kill appwrite_runtimes14 remaining items
redarflap commentedon Dec 4, 2022
@netapy
Are you by any chance running a docker version installed through snapd on Ubuntu?
After lots of testing, i noticed, that the functions are far less likely to get stuck on my Docker Desktop Windows environment.
So I tested different things and finally I replaced the snapd version with the version from the official Docker repo, while copying all my volumes over and it seems much more stable now.
When spamming a simple function 10.000 times (10 parallel), it still fails between 0-50 times. But it seems that now at least it takes much more effort to pull down the whole system.
I'm running Ubuntu 22.04 LTS in a VM with 4 cores/4Gb.
Before: Docker installed via OS installer/snap (20.10.17)
Now: Docker installed using Docker repo (20.10.21)
Some other interesting things that i noticed..
I got two functions
1.) When spamming the testFunction too hard (like 20 in parallel), often it is the monitoring function that gets completely stuck, and fails to recover indefinitely, while the testFunction is still able to create Documents.
Only after waiting some minutes and starting calling the testFunction again (or occasionally even refreshing the web console) the monitoring function suddenly starts working again.
2.) Functions that don't access the appwrite API don't seem to be affected by those problems at all.
So to me it seems like the problem (at least in my case) lies somewhere between the runtime container and the appwrite API, which causes it to randomly get stuck if stressed too much.
And it recovers most of the time, but not always.
Also it can still work for one function, but not for another one.
Plus, causing another unrelated call on the API, sometimes gets everything running again.
redarflap commentedon Dec 4, 2022
Another thing i noticed just now:
Increasing _APP_WORKER_PER_CORE also seems to help quite a bit to get rid of this.
I set it from 6 to 12 and now i get much less failed executions, despite spamming 15 parallel executions.
Well, unfortunately it's still happening from time to time, even under less load. I'm out of ideas...
netapy commentedon Dec 5, 2022
@redarflap thanks for your input.
Yes I am running my server on Ubuntu 22.04LTS, but my Docker always was from the official repository..
I have found that when I decreased the
function timeoutsomewhere between 5-10 seconds, my server would not crash anymore, only the function(s).I tried out the solution with the
_APP_WORKER_PER_COREbut it doesn't seem to fix it, I still get random functions that don't launch, rendering the following error :An internal curl error has occurred within the executor! Error Msg: Operation timed outOn the logs of the executor container, I get the following :
Are your error logs on the Appwrite executor the same as mine ?
I also noticed that only the functions that work with the Appwrite API get this kind of error/freeze.
I tried rewriting my functions in Node JS (previously Python) but that doesn't change a thing.
A similar issue is opened I believe : #2940
TheDarkX commentedon Jan 3, 2023
Intermittent.
Appwrite version: v:0.15.2.402
Windows WSL 2
Docker Version: 4.10.1 (82475)
Server spec: 4cores 8gb rams
Function runtime: Node16
No logs from runtime container
docker compose logs appwrite-executor

Based on users above commented, looks like this is still occurring on latest version.
Upgrading my Appwrite version to latest might have minor chances being fixed.
but I'll try.
This is a function that aggregate and generate an end day report which have dozen of loops.
Noticed that after continuous 4-5 execution in a row, the function failed to perform and resulted Operation Timed Out error.
Also checked the x-ratelimit-limit = 60 & x-ratelimit-remaining = 54, nothing seems related to rate limit.
@eldadfux apologize for the ping.
Appwrite Cloud Function is a crucial feature.
Hope someone look into this seriously.
I will deep dig the mentioned .php line error when leisure.
Edit: 4 Jan 2023
tried docker compose down && docker compose up -d
and trigger the function execution continuously 10 times + until it Timed Out, maybe redis cache issue.
stnguyen90 commentedon Jan 6, 2023
@TheDarkX, I tried creating dozens of executions of:
but they all executed fine:
Is there some promise in your code that isn't resolving? Perhaps you could try adding
console.stdlog()(yes,stdlog) and check the runtime container logs?garvitomer commentedon Feb 2, 2023
Hi,
I am facing the same issue in production now. Is there any temporary work around for this?
stnguyen90 commentedon May 12, 2023
@netapy, are you still experiencing the problem after adding the try/except?
netapy commentedon May 15, 2023
@stnguyen90
Should have came back to share it but it seems that I kind of solved my problem by setting the
_APP_FUNCTIONS_INACTIVE_THRESHOLDappwrite env variable to a month or so.The constant restart of the function apparently caused the crashes.
Not sure about it though but it seems more stable since then.
pomarec commentedon May 24, 2023
It does not look like an issue you should close to me. Is there a fix I missed ?
FYI, we had to completely switch to a docker based node backend to satisfy our client as the cloud functions were not reliable.
Tweaking _APP_FUNCTIONS_INACTIVE_THRESHOLD might be a workaround but it also has its reason to exist and to be used.
byawitz commentedon May 31, 2023
Hey @stnguyen90 , found a way to reproduce it with a clear use-cases. And, I think maybe there is a solution to overcome it.
Is there any option to reopen the issue and get it reassigned?
Thanks
dokind commentedon Nov 2, 2023
_APP_FUNCTIONS_INACTIVE_THRESHOLD to how much ?
stnguyen90 commentedon Aug 21, 2024
Will use #5629 to track this.