Cloud functions synced multiple times

Using this script to save our cloud functions, we noticed that the aftersave functions were saved in the cloud function Moralis UI more than once.

moralis-admin-cli watch-cloud-folder --moralisApiKey KEY --moralisApiSecret SECRET --moralisSubdomain --autoSave 1 --moralisCloudfolder src\blockchain\cloud\

Some even up to 5 times. After we found this issue we cleared all the cloud functions and reran the script.wondering why this might have happened and how to prevent it in the future.

what you mean by cloud function saved more than once?

afterSave executed up to 4 times, where it should only have executed once. Issue has returned.

you could set a flag so that the code doesn’t execute multiple times, afterSave should call when it is any update to that table rows

thanks. looking into the request object, just strange that this is only happening now.

is there any reason that a tables rows would be updating besides the handled confirm flag upon creation?

important to note that this happens after an event is handled with eventsync

do you have a nitro server now? (the one with coreservices)

in that case a create is also replaced with an update

we have coreservices plugin, I believe that could be relevant to the behavior. however we are faced with a challenge, how can we accomplish managing a flag variable using event sync? Ideally we do not want to edit the table that receives the event. Also how does this factor into an afterSaving calling 3-4 times due to an event listener? The event synced is only producing 1 more row to the table.

you could add a flag in the same table, it will trigger after save again

we still do not know why the event is created/updated multiple times? If Moralis handles async functions in different threads, its possible that we will be unable to update the flag before a function is triggered again thus creating a race condition. Please advise if this scenario is a possibility

you use an upgraded server?

you can also try to use redis if you want to implement some kind of mutex

we use an upgraded server yes. rather than diving into a mutex implementation I am just trying to get a better understanding of how events are being synced (since the expectation is of a single thread to run rather than multiple threads in the first place)

on what chain is the server? or on what chain are those events synced

also, what version of the server are you using, latest Nitro version?

tested on 0.0.345 and moving to 0.0.347 to test again after facing some technical difficulties. How can I confirm that the server is Nitro? The Role table contains coreservices is how I currently check and have assumed that all updated servers are using Nitro.

if you have coreservices plugin then it is a nitro server
only new created servers are nitro servers by default

how do we confirm our current list of plugins/install coreservices plugin? Does not seem to be offered on the currently available plugin store and is not indicated in my installed plugins list (currently empty)

it looks like that server that you have is not a nitro server

you can create a new server and test the event there, that new server will be a nitro server

1 Like

hello, I have the same problem with a nitro server
my cloud function: Moralis.Cloud.beforeSave is called multiple times for the same event

How many times it happens?