Fix machines becoming unreachable after they report IP addresses that they can't be contacted with

This commit is contained in:
Cameron Gutman 2015-10-11 14:16:38 -07:00
parent fd12e30c53
commit 79b6ec839a

View File

@ -451,7 +451,7 @@ public class ComputerManagerService extends Service {
return ComputerDetails.Reachability.OFFLINE; return ComputerDetails.Reachability.OFFLINE;
} }
private boolean pollComputer(ComputerDetails details) throws InterruptedException { private ReachabilityTuple pollForReachability(ComputerDetails details) throws InterruptedException {
ComputerDetails polledDetails; ComputerDetails polledDetails;
ComputerDetails.Reachability reachability; ComputerDetails.Reachability reachability;
@ -468,7 +468,7 @@ public class ComputerManagerService extends Service {
// If no connection could be established to either IP address, there's nothing we can do // If no connection could be established to either IP address, there's nothing we can do
if (reachability == ComputerDetails.Reachability.OFFLINE) { if (reachability == ComputerDetails.Reachability.OFFLINE) {
return false; return null;
} }
} }
@ -500,12 +500,10 @@ public class ComputerManagerService extends Service {
reachableAddr = localFirst ? details.localIp : details.remoteIp; reachableAddr = localFirst ? details.localIp : details.remoteIp;
} }
// Machine was unreachable both tries if (reachableAddr == null) {
if (polledDetails == null) { return null;
return false;
} }
// Determine the machine's reachability based on the address we reached it on
if (polledDetails.remoteIp.equals(reachableAddr)) { if (polledDetails.remoteIp.equals(reachableAddr)) {
polledDetails.reachability = ComputerDetails.Reachability.REMOTE; polledDetails.reachability = ComputerDetails.Reachability.REMOTE;
} }
@ -513,15 +511,31 @@ public class ComputerManagerService extends Service {
polledDetails.reachability = ComputerDetails.Reachability.LOCAL; polledDetails.reachability = ComputerDetails.Reachability.LOCAL;
} }
else { else {
polledDetails.reachability = ComputerDetails.Reachability.UNKNOWN;
}
return new ReachabilityTuple(polledDetails, reachableAddr);
}
private boolean pollComputer(ComputerDetails details) throws InterruptedException {
ReachabilityTuple initialReachTuple = pollForReachability(details);
if (initialReachTuple == null) {
return false;
}
if (initialReachTuple.computer.reachability == ComputerDetails.Reachability.UNKNOWN) {
// Neither IP address reported in the serverinfo response was the one we used. // Neither IP address reported in the serverinfo response was the one we used.
// We'll do a fast poll now to see if the machine is reachable via either of // Poll again to see if we can contact this machine on either of its reported addresses.
// these. ReachabilityTuple confirmationReachTuple = pollForReachability(initialReachTuple.computer);
polledDetails.reachability = fastPollPc(polledDetails.localIp, polledDetails.remoteIp); if (confirmationReachTuple == null) {
LimeLog.info("Fast poll for reachability returned "+reachability.toString());
if (polledDetails.reachability == ComputerDetails.Reachability.OFFLINE) {
// Neither of those seem to work, so we'll hold onto the address that did work // Neither of those seem to work, so we'll hold onto the address that did work
polledDetails.localIp = reachableAddr; initialReachTuple.computer.localIp = initialReachTuple.reachableAddress;
polledDetails.reachability = ComputerDetails.Reachability.LOCAL; initialReachTuple.computer.reachability = ComputerDetails.Reachability.LOCAL;
}
else {
// We got it on one of the returned addresses; replace the original reach tuple
// with the new one
initialReachTuple = confirmationReachTuple;
} }
} }
@ -529,7 +543,7 @@ public class ComputerManagerService extends Service {
String savedMacAddress = details.macAddress; String savedMacAddress = details.macAddress;
// If we got here, it's reachable // If we got here, it's reachable
details.update(polledDetails); details.update(initialReachTuple.computer);
// If the new MAC address is empty, restore the old one (workaround for GFE bug) // If the new MAC address is empty, restore the old one (workaround for GFE bug)
if (details.macAddress.equals("00:00:00:00:00:00") && savedMacAddress != null) { if (details.macAddress.equals("00:00:00:00:00:00") && savedMacAddress != null) {
@ -704,4 +718,14 @@ class PollingTuple {
this.computer = computer; this.computer = computer;
this.thread = thread; this.thread = thread;
} }
}
class ReachabilityTuple {
public final InetAddress reachableAddress;
public final ComputerDetails computer;
public ReachabilityTuple(ComputerDetails computer, InetAddress reachableAddress) {
this.computer = computer;
this.reachableAddress = reachableAddress;
}
} }