C.server.update is going into an infinite loop
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-18-2023 05:34 AM
Whenever i am using c.server.update() , and checking in service portal it is going in an infinite loop and crashing the site. What to do
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-18-2023 12:03 PM
c.server.update() is a synchronous function, which means that it will not return until the update is complete. If you call this function in an infinite loop, it will keep updating the server-side state and never return which can cause the site to crash.
To avoid this, you need to make sure that the c.server.update() function is only called once. You can do this by using a flag to keep track of whether or not the update has been called. The following code shows how to do this:
var updateCalled = false;
function updateServerState() {
if (!updateCalled) { c.server.update(); updateCalled = true; } }
In this code, the updateServerState() function checks to see if the updateCalled flag is set.
If it is not set, then the function calls the c.server.update() function and sets the updateCalled flag to true.
Please, don't forget to mark my answer as correct if it solves your issue or mark it as helpful if it is relevant for you!
Regards,
Tushar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-18-2023 12:11 PM
check condition of "For" or "While" loop inside which c.server.update() is getting called , try to debug using if condition instead of "For" or "While" it will get called once.