Fix bug: state not updated when GRPC auto reconnect to the same server (#3181)

This commit is contained in:
kezhenxu94 2019-07-29 12:57:07 +08:00 committed by 吴晟 Wu Sheng
parent d66f775fe5
commit 7958ba9aff
2 changed files with 12 additions and 1 deletions

View File

@ -19,6 +19,7 @@
package org.apache.skywalking.apm.agent.core.remote;
import io.grpc.Channel;
import io.grpc.ConnectivityState;
import io.grpc.ManagedChannel;
import io.grpc.ManagedChannelBuilder;
import io.grpc.netty.NettyChannelBuilder;
@ -73,6 +74,10 @@ public class GRPCChannel {
return originChannel.isShutdown();
}
public boolean isConnected() {
return originChannel.getState(false) == ConnectivityState.READY;
}
public static class Builder {
private final String host;
private final int port;

View File

@ -105,9 +105,15 @@ public class GRPCChannelManager implements BootService, Runnable {
.build();
notify(GRPCChannelStatus.CONNECTED);
reconnect = false;
} else if (managedChannel.isConnected()) {
// Reconnect to the same server is automatically done by GRPC,
// therefore we are responsible to check the connectivity and
// set the state and notify listeners
notify(GRPCChannelStatus.CONNECTED);
reconnect = false;
}
reconnect = false;
return;
} catch (Throwable t) {
logger.error(t, "Create channel to {} fail.", server);