if multicast socket closes, try and restart it

also, throttle on socket failures, so it won't spin out of control...
relates to #2783
This commit is contained in:
Shay Banon 2013-03-19 11:20:47 +01:00
parent f4a212420b
commit d5beea4bba
1 changed files with 20 additions and 2 deletions

View File

@ -361,7 +361,23 @@ public class MulticastZenPing extends AbstractLifecycleComponent<ZenPing> implem
continue;
} catch (Exception e) {
if (running) {
logger.warn("failed to receive packet", e);
if (multicastSocket.isClosed()) {
logger.warn("multicast socket closed while running, restarting...");
// for some reason, the socket got closed on us while we are still running
// make a best effort in trying to start the multicast socket again...
threadPool.generic().execute(new Runnable() {
@Override
public void run() {
MulticastZenPing.this.stop();
MulticastZenPing.this.start();
}
});
running = false;
return;
} else {
logger.warn("failed to receive packet, throttling...", e);
Thread.sleep(500);
}
}
continue;
}
@ -407,10 +423,12 @@ public class MulticastZenPing extends AbstractLifecycleComponent<ZenPing> implem
handleNodePingRequest(id, requestingNodeX, clusterName);
}
} catch (Exception e) {
if (running) {
logger.warn("unexpected exception in multicast receiver", e);
}
}
}
}
@SuppressWarnings("unchecked")
private void handleExternalPingRequest(Map<String, Object> externalPingData, XContentType contentType, SocketAddress remoteAddress) {