lichess-bot-devs / lichess-bot

A bridge between Lichess bots and chess engines
GNU Affero General Public License v3.0
745 stars 440 forks source link

Backing off play game #754

Closed EmptikBest closed 1 year ago

EmptikBest commented 1 year ago

Describe the bug Doesnt play move in correspondence, backing off play game

To Reproduce No idea, just happened out of nowhere.

Expected behavior To play the game?

Logs I ran it with -v, here is the log: https://gist.github.com/EmptikBest/9fd8e4cd3e183e0130f0f38628b16913

Desktop (please complete the following information): OS: Windows 10 Enterprise Python version: Python 3.10.11 Additional context ...

MarkZH commented 1 year ago

An example of the cause of this issue from the posted log is the line below:

2023-06-25 10:03:24,751 urllib3.connectionpool DEBUG https://lichess.org:443 "GET /api/bot/game/stream/xnlZVFHD HTTP/1.1" 429 1729

The 429 is an error status that indicates that lichess-bot is hitting rate limits for the endpoint /api/bot/game/stream. As can be seen in the relevant function (lichess.get_game_stream()), there is no check for 429 rate limiting. [note]

We'll start working on a fix for this.

[note] The function lichess.get_event_stream() also has this problem, but it is only called once per session and once per lichess site reset, so it shouldn't be a problem (although putting the same fix on it should be trivial).

EmptikBest commented 1 year ago

So, by the time you fix this, should I set checkin_period to a higher value? It is at 10 right now as I rarely open lichess-bot to play a move in a correspondence game. Will that fix the problem for now? If that is the problem, maybe you should make the minimum amount for that 60, or 1 minute.

EmptikBest commented 1 year ago

I also left it on overnight today, so maybe that is causing the rate limit?

MarkZH commented 1 year ago

I think 10 seconds is probably too fast (the ping rates that trigger the error are kept secret). Lichess only expects the game stream to be called once per game, so getting the game stream every 10 seconds looks suspicious.

Setting a minimum time is probably a good idea.

The PR above will pause for one minute if the request causes a 429 error. This should allow for faster correspondence check-ins since the 429 errors should become less frequent. Please try it out with the same 10 second check-in time and let us know what happens.

EmptikBest commented 1 year ago

Same error I think, here is the log that was in lichess_bot_auto_logs: https://gist.github.com/EmptikBest/8a441b164ffb6f45bfdae6014a12cd4c

MarkZH commented 1 year ago

I saw that the error message changed, which is a good sign. Try leaving it running for at least a minute. After the first 429 error, you should see RateLimited errors in the log with a message like `Will retry in 60 seconds." Once that time runs down, it will try to start the game again on the next correspondence check in.