OpenTTD / OpenTTD

OpenTTD is an open source simulation game based upon Transport Tycoon Deluxe
https://www.openttd.org/
Other
6.02k stars 843 forks source link

Fix #12655, 4f6d75f: inconsistent state in client list and potential crash asfter client leaves #12660

Closed rubidium42 closed 2 weeks ago

rubidium42 commented 3 weeks ago

Motivation / Problem

Fixes #12655.

The client list has a cache of the buttons that can be clicked. This is invalidated when the client's connection is closed. However, since 4f6d75f the actual deleting of the NetworkClientInfo is deferred.

This meant that the rebuilding of the cache happened when the client info still existed, and then the UI would be drawn with an out-of-date cache. When the client was not a spectator, this would make the button for the spectator "group" in the UI have functionality related to the client of the previous row. Running any of those commands will cause a crash.

Description

Just do the invalidating in the destructor after the client info has been removed.

Limitations

Tangentially related, the UI at the server will also show clients that have not fully joined yet. This could in theory lead to similar issues. However, solving those cases are far less trivial; the server simply allocated the client info too early for most uses of the client info, but allocating it later will cause duplicate work.

With master this issue is a lot smaller as the client info is allocated after authorizing to the game, and there is no password authorization for companies any more. With many clients waiting to join or slow joiners this could in theory still be a problem.

Checklist for review

Some things are not automated, and forgotten often. This list is a reminder for the reviewers.