Halite-III icon indicating copy to clipboard operation
Halite-III copied to clipboard

Process termination in game engine

Open rlee287 opened this issue 7 years ago • 0 comments

Currently processes are forcefully terminated at the end of the game.

https://github.com/HaliteChallenge/Halite-III/blob/7b7deb7ffed0dde878c1348783a063d657d6dbef/game_engine/networking/unix/UnixConnection.cpp#L89-L91

https://github.com/HaliteChallenge/Halite-III/blob/7b7deb7ffed0dde878c1348783a063d657d6dbef/game_engine/networking/win32/WinConnection.cpp#L99-L110

The use of SIGKILL inside UnixConnetion.cpp forcibly shuts down the process without giving it a chance to clean up. Thus, atexit handlers, such as the ShutdownHooks inside Log.java of the Java kit, do not have a chance to run. While I am not as familiar with process signalling on Windows, this article form Dr. Dobbs suggests that TerminateProcess in WinConnection.cpp is equally dangerous.

My suggestion would be using a gentler process of sending SIGTERM (and its Windows equivalent) to give the process a chance to clean up, and then using forcible termination after a short delay if the process hasn't exited by then. This allows higher level languages to perform internal cleanup operations and would also allow users to write their own cleanup functions, e.g. to flush log files.

rlee287 avatar Oct 25 '18 16:10 rlee287