FO hang on cancel SP game galaxy setup

Programmers discuss here anything related to FreeOrion programming. Primarily for the developers to discuss.

Moderator: Committer

Post Reply
Message
Author
User avatar
Dilvish
AI Lead and Programmer Emeritus
Posts: 4768
Joined: Sat Sep 22, 2012 6:25 pm

FO hang on cancel SP game galaxy setup

#1 Post by Dilvish »

I'm not sure just when this started, but for a while at least the game has been hanging if I cancel the single player galaxy setup dialog; I have to manually kill the server to get past that. I finally looked into it and found out the problem, with an easy/rough solution I implemented for myself at least on an interim basis, and there are couple others that may be better/cleaner.

The issue arises because when the SP GalaxySetupWnd is brought up, the server has been started and needs to be killed. The code IN HumanClientApp::NewSinglePlayerGame() currently calls HumanClientApp::KillServer() for that, which in turn calls m_server_process.Kill(), which calls Process::Kill(), in turn calling Process::Impl::Kill() if there is actually a process active, which in turn sends a SIGHUP signal and then calls waitpid to wait for the process to die, which in this case it doesn't and so the perpetual hang. The problem is that SIGHUP is a gentle kill signal requiring that the receiving process be listening for that signal so it can make a clean shutdown. Our processes do not seem to actually listen for that signal (I see no indication anywhere that they try to), and so the signal does nothing. We don't normally see this problem because normally the server has already been told to shutdown by a call to m_networking.SendMessage(ShutdownServerMessage(m_networking.PlayerID())); in HumanClientApp::EndGame().

(A) So, the simple solution I did for myself is just to change Process::Impl::Kill() to send a SIGKILL instead of a SIGHUP, because at least on Linux I don't really need the server to do any cleanup. I am a little concerned though that on Windows killing the server without having it close the logger file might possibly create a filesystem issue, but if that's not a worry then this seems a fine solution.

(B) Just simply changing the HumanClientApp::NewSinglePlayerGame call to HumanClientApp::KillServer() into a call to HumanClientApp::EndGame doesn't quite solve it, because although the server has been started the client has not actually connected to it yet, and so EndGame just skips over the part about sending the server a nice shutdown message. But, if we made HumanClientApp::NewSinglePlayerGame be sure to first connect to the server then a call to EndGame should work out fine. It seems a bit odd to connect just to issue the shutdown, but this is a cleaner solution than using SIGKILL.

(C) A third solution of course would be to have our processes be listening for SIGHUP and deal with it, but I don't currently know how to make it do that and (A) or (B) seems good enough to me.
If I provided any code, scripts or other content here, it's released under GPL 2.0 and CC-BY-SA 3.0

User avatar
Geoff the Medio
Programming, Design, Admin
Posts: 13587
Joined: Wed Oct 08, 2003 1:33 am
Location: Munich

Re: FO hang on cancel SP game galaxy setup

#2 Post by Geoff the Medio »

I think connecting to the server immediately, and sending a suitable message to the server if the setup dialog is cancelled, would be best. Then the server would terminate itself, without needing to use a potentially problematic OS kill command...

User avatar
Dilvish
AI Lead and Programmer Emeritus
Posts: 4768
Joined: Sat Sep 22, 2012 6:25 pm

Re: FO hang on cancel SP game galaxy setup

#3 Post by Dilvish »

OK, got it working. The server wasn't wanting to accept the Shutdown message without the player having been established as Host or even an EstablishedPlayer, so I had it make an exception if the message comes from the sole connected player who is also on the same machine as the host. Due to some indent changes it looks like many more lines changed than really did, so I also attached an ignore-whitespace patch to show the real changes a bit more clearly. How's this look to you?
Attachments

[The extension patch has been deactivated and can no longer be displayed.]

[The extension patch has been deactivated and can no longer be displayed.]

If I provided any code, scripts or other content here, it's released under GPL 2.0 and CC-BY-SA 3.0

User avatar
Dilvish
AI Lead and Programmer Emeritus
Posts: 4768
Joined: Sat Sep 22, 2012 6:25 pm

Re: FO hang on cancel SP game galaxy setup

#4 Post by Dilvish »

I've gone ahead and committed this but am of course still open to suggestions for changes.
If I provided any code, scripts or other content here, it's released under GPL 2.0 and CC-BY-SA 3.0

User avatar
Geoff the Medio
Programming, Design, Admin
Posts: 13587
Joined: Wed Oct 08, 2003 1:33 am
Location: Munich

Re: FO hang on cancel SP game galaxy setup

#5 Post by Geoff the Medio »

I won't really have time to look at this for a few days at least...

User avatar
Vezzra
Release Manager, Design
Posts: 6095
Joined: Wed Nov 16, 2011 12:56 pm
Location: Sol III

Re: FO hang on cancel SP game galaxy setup

#6 Post by Vezzra »

Well, it's in the test builds now so I guess we'll get some feedback if there are any problems :D

Post Reply