Skip to content

Commit

Permalink
elastic#26701 retry in org.elasticsearch.transport.MockTcpTransport#…
Browse files Browse the repository at this point in the history
…connectToChannels
  • Loading branch information
original-brownbear committed Sep 23, 2017
1 parent d87ab67 commit feb8f30
Showing 1 changed file with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package org.elasticsearch.transport;

import java.net.ConnectException;
import org.apache.lucene.util.IOUtils;
import org.elasticsearch.Version;
import org.elasticsearch.action.ActionListener;
Expand Down Expand Up @@ -181,14 +182,28 @@ protected NodeChannels connectToChannels(DiscoveryNode node, ConnectionProfile p
final MockChannel[] mockChannels = new MockChannel[1];
final NodeChannels nodeChannels = new NodeChannels(node, mockChannels, LIGHT_PROFILE); // we always use light here
boolean success = false;
final MockSocket socket = new MockSocket();
MockSocket socket = new MockSocket();
try {
final InetSocketAddress address = node.getAddress().address();
// we just use a single connections
configureSocket(socket);
final TimeValue connectTimeout = profile.getConnectTimeout();
try {
socket.connect(address, Math.toIntExact(connectTimeout.millis()));
int retries = 0;
while (true) {
++retries;
try {
socket.connect(address, Math.toIntExact(connectTimeout.millis()));
break;
} catch (final ConnectException ex) {
if (retries > 10) {
throw ex;
}
IOUtils.close(socket);
socket = new MockSocket();
configureSocket(socket);
}
}
} catch (SocketTimeoutException ex) {
throw new ConnectTransportException(node, "connect_timeout[" + connectTimeout + "]", ex);
}
Expand Down

0 comments on commit feb8f30

Please sign in to comment.