Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Process termination in game engine #99

Open
rlee287 opened this issue Oct 25, 2018 · 0 comments
Open

Process termination in game engine #99

rlee287 opened this issue Oct 25, 2018 · 0 comments

Comments

@rlee287
Copy link

rlee287 commented Oct 25, 2018

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

UnixConnection::~UnixConnection() noexcept {
kill(-process, SIGKILL);
}

WinConnection::~WinConnection() noexcept {
if (read_pipe != INVALID_HANDLE_VALUE) {
CloseHandle(read_pipe);
}
if (write_pipe != INVALID_HANDLE_VALUE) {
CloseHandle(write_pipe);
}
if (process != INVALID_HANDLE_VALUE) {
TerminateProcess(process, 0);
CloseHandle(process);
}
}

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant