quadra-game / quadra

An addictive action puzzle game with single player and multiplayer capabilities (Internet or LAN).
GNU Lesser General Public License v2.1
28 stars 18 forks source link

make sure we don't cache IPs too much #12

Closed pphaneuf closed 10 years ago

pphaneuf commented 10 years ago

Some servers disappeared from the master server at some point, and reappeared after they had been restarted.

The master server is currently on a dynamic IP, with the DNS being updated, but if there is too much IP address caching, this would cause this kind of problem.

pphaneuf commented 10 years ago

Is there any way to make Quadra respect the TTL of the DNS? And if one of you runs the master server, then you may want to reduce the TTL.

pphaneuf commented 10 years ago

Looks like Qserv::http_addr (and Qserv::http_port) are the culprit, in source/qserv.cpp. If we just cleared them on any kind of error, it should probably work just fine (unless whoever takes over the IP of qserv also has a qserv in the same location!).

Stéphane, you wrote that, could you give that a quick look? It should be really easy to fix, if there is a good place to clear the cache...

pphaneuf commented 10 years ago

Why do you cache the IP? Doing a DNS lookup on every request should avoid such problems.

I changed in qserv.cpp (line 227) the section

if(http_addr) req=new Http_post(host, http_addr, http_port, path); else req=new Http_post(host, port, path);

to

req=new Http_post(host, port, path);

and the problem with the dynamic IP seems to be gone. At least this config runs since yesterday on the NX servers without a problem.

pphaneuf commented 10 years ago

That will indeed prevent this exact problem, but the game server might experience momentarily lag when it does a qserv update, since the DNS resolution is done in a blocking way on Linux (argh).

The best way to fix that would be to remove the caching code entirely (similarly to what you've done), but make the DNS resolution asynchronous, so that the game is not slowed down. But that's a bigger project, if only to figure out what's going on exactly in the current code (Stéphane wrote this what, seven, eight years ago?)...

What I have in mind is more of an easy fix that will give us most of the result with a very small scope: keep using the cache (so lag is avoided), but when we fail to update qserv, for any reason, clear the cache. If, for some bad luck, whoever picks up the old IP address of the master server when it changes IP also has a qserv, then we're screwed. I figure the odds are pretty low. :-)

Even then, we could put in a TTL (time to live), where we're use the cache up to X times, then clear it.

pphaneuf commented 10 years ago

This one is pretty important, as it prevents servers from updating themselves. I got the NX server admin, piezza, to put in a temporary workaround in his version of Quadra, since he had a home-built version from Subversion anyway, but this is broken.

pphaneuf commented 10 years ago

Should be fixed by r495.

pphaneuf commented 10 years ago

Merged into the quadra-sdl branch with r496.