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

Server exiting to main menu hangs client #7462

Closed
SamuXarick opened this issue Apr 2, 2019 · 5 comments
Closed

Server exiting to main menu hangs client #7462

SamuXarick opened this issue Apr 2, 2019 · 5 comments

Comments

@SamuXarick
Copy link
Contributor

Version of OpenTTD

1.9.0

Expected result

Client exits to main menu

Actual result

Client hangs

Steps to reproduce

(Server) Create a non-dedicated server
(Client) Join server
(Server) Exit to main menu
(Client) hangs

@SamuXarick
Copy link
Contributor Author

EDIT: Oh snap, client actually reached main menu as I was typing this. It really took a long time though, and looked like it was hanged.

@SamuXarick
Copy link
Contributor Author

It was due to my savegame format, lzma:9 and map size being 4096x4096. It could display a Zzz cursor though.

@LordAro
Copy link
Member

LordAro commented Dec 31, 2019

I can confirm this. More so, it would appear that the emergency network save (netsave.sav) happens twice, compounding the issue. (FOO debugs show where ClientNetworkEmergencySave is called from)

FOO: virtual NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_SHUTDOWN(Packet*)
dbg: [net] Client: Performing emergency save (netsave.sav)
FOO: void ClientNetworkGameSocketHandler::ClientError(NetworkRecvStatus)
dbg: [net] Client: Performing emergency save (netsave.sav)

Not yet sure why the whole game hangs when it's doing this emergency save - looks like it might just be because it's not threaded?

@LordAro
Copy link
Member

LordAro commented Jan 2, 2020

Seems like it might not be possible to thread the save in this case - as nonthreaded would mean that the game goes back to the title screen and loads the title game, which would corrupt the save/saving process. Probably.

Caused by #6796

@TrueBrain
Copy link
Member

I agree with @LordAro's analysis. This simply happens because an emergency save is happening. While normally all saves are done threaded, so you can continue playing, this happens in such a place we don't have that luxury.

I think the only way to solve this, would be to add an additional game-mode. It is a bit complicated, let's see if I can write it down:

  • Drawing is done via the main GameLoop. If that is not looping, drawing is not done. (even with threaded drawing, the GameLoop is in control when the thread is allowed to draw again)
  • This Emergency Save is added in a place that is busy doing clean-up of the server closing socket. It cannot return to the GameLoop until it is done, as other work needs to be done too

I think the only way out is to make a new game-mode, that knows it is doing an Emergency Save, and knows where to go to after it is done. This is a lot of work for a very rare case. And it will not be pretty.
Other solutions would be to restructure our whole code to be more async .. but that is not happening any time soon :)

As such, I am going to close this ticket with: working-as-intended. I know it is a bit annoying, but better to have the savegame than to not have the savegame at all :)

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

No branches or pull requests

3 participants