samp-discord-connector
samp-discord-connector copied to clipboard
[Improvement]: Websocket actions should be rate limited
Related to issue in #204 - this code was found guilty of discord closing connection;
for(new i=0;i<312;i++) if(i!=74) if(i)
{
/*classes[classid]=i;
classid++;*/
SetTimer("BotStatus", 5000, true);
AddPlayerClass(i,488.1703,-14.2043,1000.6797,17.7887,-1,-1,-1,-1,-1,-1);
}
// Somewhere else:
public BotStatus(playerid)
{
new msr[50];
format(msr, sizeof(msr), "%d players in server.", onlineplayers2);
DCC_SetBotActivity(msr);
}
As you can see, the timer which is set here, is called about 310 times - causing the "5 times within 20 second rate limit" to be hit rather instantaneously - and discord closes the connection. The code it called was updating the Bot Activity text with "online players".
[12/21/21 22:48:22] [plugins/discord-connector] Discord terminated websocket connection; reason: Rate limited. (4008)
[12/21/21 22:48:22] [plugins/discord-connector] Can't write to Discord websocket gateway: Operation canceled (125)
Onwards, the server ends up crashing. @vasilpayments fyi ^
Reporting for visibility after a session talking about it in the omp discord. (https://discord.com/channels/231799104731217931/231799180127895553/933330000369844314)
den
Bot is working, but I see in logs this
[01/19/22 15:34:23] [ERROR] Can't write to Discord websocket gateway: Operation canceled (125)
This is getting spammed each 40 minutes (approximately)
Can this cause server crash? Or I can ignore it?
Seems that rate limits are a thing now so I am closing this issue