Derpius / pythonsourceserverdiscordbot

Discord bot for my Python source server query library
GNU General Public License v3.0
3 stars 1 forks source link

[bug] GLua async HTTP function can't handle concurrent requests #17

Closed Derpius closed 3 years ago

Derpius commented 3 years ago

Describe the bug GLua's asynchronous HTTP function cannot handle multiple concurrent requests, which means after the new changes using HTTP() for POSTing instead of http.Post to use a proper post body instead of x-www-form-urlencoded which is the only method http.Post provides, causes the HTTP() call for Discord message long polling to run sequentially with the HTTP() call for POSTing.

This causes posted messages to be send in between GET long polling, which is 30 seconds from the last poll.

To fix this I'm going to have to use a single x-www-form-urlencoded parameter for json, allowing me to use http.Post which runs separately from async HTTP() calls.

Additionally, this slowdown of HTTP() doesn't appear to affect other GLua addons, as internally the http library merely abstracts calls of HTTP(), and yet calling http library methods from inside relay.lua doesn't suffer from the same issue as using HTTP().

Additional context While low level UDP communication would be far more suited to something like this, requiring a binary module back end for the relay client would increase the complexity (also means I would have to write a protocol for UDP relaying, and implement a multi threaded socket server in python).

Derpius commented 3 years ago

Ok this issue appears intermittent, closing for now until I'm sure this was actually the cause of the issue I observed

Derpius commented 3 years ago

It seems the actual cause was sv_hibernate_think being 0, meaning when the server is in hibernation (no players/bots online) it will stop calling Tick and Think hooks among other things like timers not working, meaning messages were delayed until either a player/bot joined, or the relay was stopped which triggers a final manual POST of the cache.

Fixed in 4520850349e348211e4dc6610ff506eff1c9061e