3 ms·
One thread per connection might not scale but in this case other things could be done to mitigate the potential problem before re-writing the whole server. Per
by rdtsc 16y ago
One thread per connection might not scale but in this case other things could be done to mitigate the potential problem before re-writing the whole server. Perhaps use a special encoding for the authentication that doesn't use unbounded strings for username but a fixed size array of chars? Then maybe start a timer and if authentication isn't performed during a given time period, disconnect that client.
- blake8086 16y agoSay you kill connections after 1 second (pretty aggressive) and you can hold 1,000 connections open (that's a fair number of threads) All I have to do is create 1,000 connections per second and I'll hog all your thread resources. That's not too hard to do.
- wtallis 16y agoKilling connections after a full second has elapsed probably isn't at all aggressive in the context of a game server. If the connection is legit but takes a full second to send authentication info, then there's no hope for the game actually being playable over that connection.
- kpreid 16y agoDepends on the game. Minecraft is hardly twitchy, especially if you're building, not fighting; the client proceeds as if each action has already happened, so you don't have to wait for the roundtrip between actions.
- rdtsc 16y ago1 second might not be too agressive for initial log-in -- that is where the real problem he is trying to solve is. If the username + password are not unbounded strings, but say, fit in an array of a 100 chars, then you should expect to get that data a lot sooner than 1 second (maybe 200ms?). So then maybe you can handle 5K connections... Yeah you are right, this is still not as good as a good async framework but the point was that some smaller things can be tried before a complete re-write. It might just be good enough.
- MostAwesomeDude 16y agoNobody has really publicly talked about it, but there is now code in the Notchian and CraftBukkit servers to limit connections from single IPs to once every 5 seconds, and to disconnect slow logins by killing the thread after 30 seconds, effectively limiting the attack to 6 threads used per attacker. To actually bring down a server this way would then take 100 attackers or so. This really is just a proof of concept, after all, and not a tool which can bring down entire servers single-handedly. (At least, not anymore.)