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

Engine isn't closed properly on invalid options #903

Closed AttackingOrDefending closed 7 months ago

AttackingOrDefending commented 7 months ago

Describe the bug If we find a problem while running the initial check to see if the engine supports the options provided by the user, we raise an error but lichess-bot hangs instead of closing. I had to press Ctrl+C for the engine to close, which is why there is a 13 seconds delay in the log file.

My guess is that it is caused by this line.

To Reproduce Steps to reproduce the behavior:

  1. Add Hash2: 2 to uci_options
  2. Run lichess-bot using Stockfish
  3. See error

Expected behavior lichess-bot terminates properly instead of hanging.

Logs recent.log

Desktop (please complete the following information):

Additional context None

MarkZH commented 7 months ago

It seems the problem is that the line you highlighted is never reached. Since the engine class __init__() methods never complete due to the exception raised by self.engine.configure(). This means that the __enter__() method called by with never completes, which prevents __exit__() from being called. So, the connection to the engine is never closed.