Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Using
WeightRampingUpStrategy
with AbstractEndpointSelector
can f…
…ail to select initial endpoints (#5752) Motivation: Following the change of #5693, now calling `EndpointGroup#selectNow` may return `null` if the `RampingUpEndpointWeightSelector#updateEndpoints` is not completed yet since updates are always scheduled on the event loop. https://github.com/line/armeria/blob/8bad3305a8e1843c049537395368266215245df6/core/src/main/java/com/linecorp/armeria/client/endpoint/WeightRampingUpStrategy.java#L149 In addition, most `EndpointGroup` implementations use `AbstractEndpointSelector`. Whenever a change is made to the `EndpointGroup#endpoints`, [refreshEndpoints](https://github.com/line/armeria/blob/8bad3305a8e1843c049537395368266215245df6/core/src/main/java/com/linecorp/armeria/client/endpoint/AbstractEndpointSelector.java#L148) is called. The expectation here is that [updateEndpoints](https://github.com/line/armeria/blob/8bad3305a8e1843c049537395368266215245df6/core/src/main/java/com/linecorp/armeria/client/endpoint/AbstractEndpointSelector.java#L150) updates the internal state of the endpoint selector, and then pending futures invoke `selectNow` again. https://github.com/line/armeria/blob/8bad3305a8e1843c049537395368266215245df6/core/src/main/java/com/linecorp/armeria/client/endpoint/AbstractEndpointSelector.java#L148-L158 However, `WeightRampingUpStrategy` completes `updateEndpoints` asynchronously. Therefore, `pendingIf` futures may call `RampingUpEndpointWeightSelector#selectNow` although `RampingUpEndpointWeightSelector` didn't update its state yet. Consequently, some pending futures may never have a chance to be updated unless the endpoints is updated again. Modifications: - Modified `AbstractEndpointSelector#updateNewEndpoints` to return a `CompletableFuture<Void>` instead of `void` - `RampingUpEndpointWeightSelector#updateNewEndpoints` completes the returned future once the endpoints have completely updated the internal state Result: - `WeightRampingUpStrategy` works with `AbstractEndpointSelector` <!-- Visit this URL to learn more about how to write a pull request description: https://armeria.dev/community/developer-guide#how-to-write-pull-request-description -->
- Loading branch information