Fix #9501: [Network] crash when more than one game-info query was pending #9502
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation / Problem
When you have more than one query-for-game-info pending, the game crashes. This is easiest reproduced by starting a local server, and adding
127.0.0.1
and127.0.0.2
to your server-list. Close the game, restart it, click Multiplayer. Now two queries will be send out at the exact same time.Description
We piggy-backed on the client code to, after establishing a TCP connection, query the server. The client code only has a very weird and annoying to follow singleton called
my_client
. As it turns out, when it is being asked to query two different servers at the same time, it panics.To resolve the situation in a more robust way, I cut out the game-info query part from the client code, and moved it to
network_query
. This part is now responsible solely for querying the game-info of a server, and can have as many parallel connection as needed. It self-registers and self-destroys.As an additional bonus, this means we can also handle errors from servers in a bit nicer way for when a query fails. This is best seen about the code removed from the client code.
As the protocol reuses other packages to indicate issues, the server can send back 4 different packets depending on the situation on a game-info request:
game-info
, what we are after.error
, when something weird went wrong. For example, when it never saw your game-info request packet .. it will hit a timeout and close your connection. But this is really unlikely to ever happen.banned
, when your IP is banned (you won't be able to query the server in that case either; only seems fair).full
, which is already a bug on our bugtracker, but currently at a very early moment in time we validate if the server has room for you. If not, you get this packet back, and refresh fails. This of course has to be resolved, but as for now, this is still happening.Limitations
Checklist for review
Some things are not automated, and forgotten often. This list is a reminder for the reviewers.