Contract Events not firing with error: Request.message is not a function

The afterSave function is firing very inconsistently on event listeners to contracts. It will often hang and never execute, while occasionally executing right away perfectly.
While going through the logs, every time that the cloud folder is watched we are getting this error on several functions:

ERROR || 2022-01-11 19:17:31
Error initializing sync for Event “EventBSCMintSevenTwoOne”: request.message is not a function

We are also receiving an error that returns empty.,

ERROR || 2022-01-11 19:19:13

It is important to note that these contract events have been added programmatically, and not through the admin portal UI.

Note that since working with the contract events in code, we have received this error 4 times over the last few days.

Please help us fix the issue of our afterSave functions not firing. The events are successfully being added to their respective tables without issue.

you are syncing historical events too? for historical events afterSave will not be triggered

you will have to do run a separate job to process historical events if that is the case

problems persist for events in real time, as well as events that are not hooked up with historical sync.

ok, can you provide some steps on how to replicate this problem for real time events?

We believe that the problem likely has to do from watching contracts from code. Following this documentation:

We have also used it to unwatch events from code and rewatch onto the same table (Potential error point).
There are a lot of factors in play that could cause the inconsistency of our afterSave() events firing, so it is hard to determine on our end with limited logging. The errors being received are presented in the original post. Note that we are using an upgraded server.

Thanks! Appreciate all of the help that you provide @cryptokid

new error log that seems to be related to this issue, as ther error came I can no longer update the server with the problem that comes from this issue:

Any insight on how to fix this error? That seems to have to do with the node version and require() functionality

On that note I will need a server restart for continued use.

I think that I saw this error before on a forum post, don’t know where from it comes, what did you do to get that error with require and a path to moralis-admin-cli?

We believe its from moralis-admin-cli watch-cloud-folder call.

I’ve seen on one of my tests that error with Request.message is not a function and it seems that event sync didn’t started, and after a server restart it started to work, I don’t know if that error really influences event sync now

the problem in your case may also be that it is not easy to restart the server if you see that cloud code error popup

Yes, it may be the case that when receiving that error our event sync is not catching events. Restarting the server every time the error appears would not be viable in production. It seems like the issue is internal with Moralis, and that it may potentially be solved for the time being. Do let us know if you figure something out, I have provided as much detail as I can and will continue to provide information if the issue persists. Thanks again.