One of our customer has configured its ring group as following:
Ring-Group
Destination: 1001
Destination: 1002
And its follow-me extensions as following:
Follow-Me 1001
Destination: 1001
Destination: 1002
Follow-Me 1002
Destination: 1002
Destination: 1001
The above configuration leaded to a fatal infinite loop that caused FreeSWITCH / PostgreSQL / Nginx to slow down at a point where the system was almost crashed.
After investigations, I found that the root cause of the endless loop is in app/ring_groups/index.lua. The lua script creates a destination array (destinations) based on the destinations that are part of the ring group and the follow-me destinations that are parts of every follow-me destinations. The problem comes from the fact that the script loops through the destinations array that grows endlessly.
To avoid this situation (that I do not aim to prevent in the follow-me / ring group forms), I added the below function and I am adding a new destination only when it is not already present in the destination array.
So, now I add a new destination (destinations[new_key] = {}) only when destination_exists(destinations, field.destination_number) returns false.
Any comment?
Ring-Group
Destination: 1001
Destination: 1002
And its follow-me extensions as following:
Follow-Me 1001
Destination: 1001
Destination: 1002
Follow-Me 1002
Destination: 1002
Destination: 1001
The above configuration leaded to a fatal infinite loop that caused FreeSWITCH / PostgreSQL / Nginx to slow down at a point where the system was almost crashed.
After investigations, I found that the root cause of the endless loop is in app/ring_groups/index.lua. The lua script creates a destination array (destinations) based on the destinations that are part of the ring group and the follow-me destinations that are parts of every follow-me destinations. The problem comes from the fact that the script loops through the destinations array that grows endlessly.
To avoid this situation (that I do not aim to prevent in the follow-me / ring group forms), I added the below function and I am adding a new destination only when it is not already present in the destination array.
Code:
local function destination_exists(destinations, destination)
local exist = false;
for key, row in pairs(destinations) do
if row.destination_number == destination then
exist = true;
break;
end
end
return exist;
end
So, now I add a new destination (destinations[new_key] = {}) only when destination_exists(destinations, field.destination_number) returns false.
Any comment?