Skip to content

Commit

Permalink
loadbalancer-experimental: subscribe is the last thing we do in Defau…
Browse files Browse the repository at this point in the history
…ltLB constructor

Motivation:

We want all the fields initialized before we subscribe to the SD events
so if something happens and an attempt is made to close before construction
is complete we don't end up with a NPE somewhere.

Modifications:

- Move the outlier detection stream cancellation assignment to before
  the subscription.

Result:

What is the result of this change?
  • Loading branch information
bryce-anderson committed Jul 12, 2024
1 parent 821619a commit cb3c66a
Showing 1 changed file with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -164,14 +164,15 @@ final class DefaultLoadBalancer<ResolvedAddress, C extends LoadBalancedConnectio
// Maintain a Subscriber so signals are always delivered to replay and new Subscribers get the latest signal.
eventStream.ignoreElements().subscribe();
this.outlierDetector = requireNonNull(outlierDetectorFactory, "outlierDetectorFactory").apply(lbDescription);
// We subscribe to events as the very last step so that if we subscribe to an eager service discoverer
// we already have all the fields initialized.
subscribeToEvents(false);

// When we get a health-status event we should update the host set.
this.outlierDetectorStatusChangeStream = this.outlierDetector.healthStatusChanged().forEach((ignored) ->
sequentialExecutor.execute(() -> sequentialUpdateUsedHosts(usedHosts)));

// We subscribe to events as the very last step so that if we subscribe to an eager service discoverer
// we already have all the fields initialized.
subscribeToEvents(false);

LOGGER.info("{}: starting load balancer. Load balancing policy: {}, outlier detection: {}", this,
loadBalancingPolicy, outlierDetector);
}
Expand Down

0 comments on commit cb3c66a

Please sign in to comment.