Skip to content

Fix Linux server deadlock on shutdown without TTY#1203

Open
TanF12 wants to merge 1 commit intoopenmultiplayer:masterfrom
TanF12:fix-linux-nohup-shutdown
Open

Fix Linux server deadlock on shutdown without TTY#1203
TanF12 wants to merge 1 commit intoopenmultiplayer:masterfrom
TanF12:fix-linux-nohup-shutdown

Conversation

@TanF12
Copy link

@TanF12 TanF12 commented Mar 3, 2026

Fixes #1201

This PR fixes the issue where the Linux server hangs during shutdown if started without a TTY (e.g. through nohup).

When running in background std::getline(std::wcin, line) fails because stdin is redirected/closed. The console thread exits gracefully early on. However, during shutdown, ~ConsoleComponent() blindly calls pthread_cancel() on the native thread handle, causing a deadlock or segfault because the thread is already dead.

My solution:

  • Added an isRunning flag to ThreadProcData.
  • Set it to false when the thread exits the read loop.
  • Guarded the pthread_cancel call in the destructor to only execute if isRunning is true.

I've also:

  • Added #include to Server/Components/Pawn/Plugin/Plugin.cpp to fix some compilation errors on newer compilers like Clang 19 (I compiled my test build on Debian 13, but I'm not sure if that's intentional so feel free not to apply that). But it was likely missing because of stricter transitive includes in newer standard libraries

My testing process:

  • Built on Debian 13 with Clang 19.
  • Started server via nohup ./omp-server &.
  • Sent kill -15 pid. Process shuts down cleanly instead of hanging indefinitely.

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

Successfully merging this pull request may close these issues.

Linux openmp server does not shut down when it started via nohup or systemd

1 participant