Closed alfg closed 10 years ago
Here's the secret sauce: https://github.com/alfg/guildbit/blob/d00d50926e78d26a0f8dffb8ede73d08161ff9f3/app/murmur.py#L250
Needs to be battletested. Seems to be working so far.
Basically, port 50000 is a reserved port and all murmur-rest servers should have their default port set to 50000 (which was part of the plan).
This function will query a list of active ports starting from 50000, and inactive ports (if any). Inactive ports are basically a list of ports that are not in use in the range of 50000 - indexOf(-1). It will use the first available port in that list. If no "inactive" ports are open, then it'll just use the last port used + 1.
Murmur uses the last port used + 1 to create a new server. This causes an issue where potentially all ports will run out if there's constantly servers running.
server 1 = port 1 server 2 = port 2 server 3 = port 3
If server 2 is destroyed, the next server will be: server 4 = port 4
So we need some functionality in place to maintain the list of open/active ports and to reuse the next one that becomes available.