Skip to content

Commit

Permalink
fix pickfirst
Browse files Browse the repository at this point in the history
  • Loading branch information
YifeiZhuang committed Nov 9, 2023
1 parent d58cf79 commit fb97e94
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 90 deletions.
8 changes: 1 addition & 7 deletions core/src/main/java/io/grpc/internal/ManagedChannelImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -1448,13 +1448,7 @@ public AbstractSubchannel createSubchannel(CreateSubchannelArgs args) {
syncContext.throwIfNotInThisSynchronizationContext();
// No new subchannel should be created after load balancer has been shutdown.
checkState(!terminating, "Channel is being terminated");
AbstractSubchannel subchannelImp = new SubchannelImpl(args);
SubchannelStateListener rootHcListener =
args.getOption(LoadBalancer.HEALTH_CONSUMER_LISTENER_ARG_KEY);
if (rootHcListener != null) {
rootHcListener.onSubchannelState(ConnectivityStateInfo.forNonError(READY));
}
return subchannelImp;
return new SubchannelImpl(args);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ void processSubchannelState(Subchannel subchannel, ConnectivityStateInfo stateIn
case READY:
shutdownRemaining(subchannel);
addressIndex.seekTo(getAddress(subchannel));
rawConnectivityState = READY;
if (subchannelData.healthState != null) {
updateHealthState(subchannelData);
}
Expand Down Expand Up @@ -284,6 +285,7 @@ private void updateBalancingState(ConnectivityState state, SubchannelPicker pick
return;
}
rawConnectivityState = state;
concludedState = state;
helper.updateBalancingState(state, picker);
}

Expand Down Expand Up @@ -352,11 +354,12 @@ public void onSubchannelState(ConnectivityStateInfo newState) {
new EquivalentAddressGroup(addr)))
.addOption(HEALTH_CONSUMER_LISTENER_ARG_KEY, hcListener)
.build());
if (subchannel.getAttributes() == null ||
subchannel.getAttributes().get(LoadBalancer.HEALTH_PRODUCER_LISTENER_KEY) == null) {
hcListener.onSubchannelState(ConnectivityStateInfo.forNonError(READY));
SubchannelData subchannelData = new SubchannelData(subchannel, IDLE, hcListener);
subchannels.put(addr, subchannelData);
Attributes attrs = subchannel.getAttributes();
if (attrs == null || attrs.get(LoadBalancer.HEALTH_PRODUCER_LISTENER_KEY) == null) {
subchannelData.healthState = ConnectivityStateInfo.forNonError(READY);
}
subchannels.put(addr, new SubchannelData(subchannel, IDLE, hcListener));
subchannel.start(new SubchannelStateListener() {
@Override
public void onSubchannelState(ConnectivityStateInfo stateInfo) {
Expand All @@ -372,7 +375,7 @@ private SocketAddress getAddress(Subchannel subchannel) {

@VisibleForTesting
ConnectivityState getConnectivityState() {
return this.rawConnectivityState;
return this.concludedState;
}

/**
Expand Down
Loading

0 comments on commit fb97e94

Please sign in to comment.