fix overflow issue with hystrix timeout operator (#2391)

- The fix adds a necessary buffer between the rx-rs adapter and
the timeout operator introduced in AbstractCommand. Unfortunately,
the hystrix operator does not comply with RS backpressure requirements.
It will always request an unbounded demand to a source regardless of
the command consumer demand. With this commit we protect RS adapter and
downstream flow from overflow. Ideally a rework of the operator should
be planned.
This commit is contained in:
Stephane Maldini
2017-10-24 11:01:44 -07:00
committed by Spencer Gibb
parent eb07e2b058
commit a67a077906
3 changed files with 24 additions and 6 deletions

View File

@@ -44,6 +44,11 @@
<artifactId>reactor-core</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.reactivex</groupId>
<artifactId>rxjava-reactive-streams</artifactId>

View File

@@ -104,7 +104,7 @@ public class HystrixCommands {
if (this.eager) {
observable = command.observe();
} else {
observable = command.toObservable();
observable = command.toObservable().onBackpressureBuffer();
}
return RxReactiveStreams.toPublisher(observable);
}

View File

@@ -16,18 +16,19 @@
package org.springframework.cloud.netflix.hystrix;
import java.time.Duration;
import java.util.List;
import com.netflix.hystrix.exception.HystrixRuntimeException;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import com.netflix.hystrix.exception.HystrixRuntimeException;
import static org.assertj.core.api.Assertions.assertThat;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import reactor.core.scheduler.Schedulers;
import reactor.test.StepVerifier;
import static org.assertj.core.api.Assertions.assertThat;
public class HystrixCommandsTests {
@@ -75,6 +76,18 @@ public class HystrixCommandsTests {
assertThat(list).hasSize(2).contains("1", "2");
}
@Test
public void fluxWorksDeferredRequest() {
StepVerifier.create(HystrixCommands.from(Flux.just("1", "2"))
.commandName("multiflux")
.build(), 1)
.expectNext("1")
.thenAwait(Duration.ofSeconds(1))
.thenRequest(1)
.expectNext("2")
.verifyComplete();
}
@Test
public void eagerFluxWorks() {
List<String> list = HystrixCommands.from( Flux.just("1", "2"))