Closed Delorien84 closed 5 years ago
@Delorien84 can you explain the specific problem, what is the expected outcome vs what is actually happening?
Sorry for that.
It cause that Hystrix onSuccess hook is not called, that cause several problems.
circuitBreaker.errorThresholdPercentage
property.Expectation is, that Hystrix onSuccess
hook is called in all case , without using workaround described above ( .toFlux().singleOrEmpty()
)
Additional notes: When Hystrix command return empty Observable (empty Mono), it works without workaround.
See https://github.com/Delorien84/hystrix-observable-flux-bug for test case.
Hmm, why are you trying to convert a Flux to a Mono?
@spencergibb Because I call web service via WebClient that return Mono as result. As i understand with talk in 1069. What I am trying to do, is the following chain WebClient(Mono)
-> Hystrix(Observable)
-> Return(Mono)
(Hystrix does not use Single
, only Observable
and there is a API, that allows me to do). The problem is conversion from Observable
to Mono
via Mono.from(RxReactiveStreams.toPublisher(observable))
. When first item arrived to Mono
it cause cancellation of Observable
(see explanation in referenced bug). Canceled Observable
does not trigger onSuccess
handlers and Hystrix does not correctly count success event.
So for me it is confusing the org.springframework.cloud.netflix.hystrix.HystrixCommands
API, that has toMono()
method, but it does not work as user expect. WebClient
return Mono
, so I naturally call HystrixCommands.toMono()
. I would recommend one of the following:
toMono()
method, to contains: toFlux().singleOrEmpty()
HystrixCommands
- If input Publisher<T>
emits no value (like Mono<Void>
) it is safely to use toMono()
. If emits one item (like Mono<T>
) user has to use toFlux().singleOrEmpty()
(making sure that underlying Observable
is not canceled) . If emits multiple values it is safe to use toFlux()
but make sure, that any operation on that Flux
does not cause subscription cancellation.@smaldini any ideas?
This module has entered maintenance mode. This means that the Spring Cloud team will no longer be adding new features to the module. We will fix blocker bugs and security issues, and we will also consider and review small pull requests from the community.
Hi, I have discovered strange behavior when using Flux stream with Hystrix (using
Observable
command viaorg.springframework.cloud.netflix.hystrix.HystrixCommands
.I have following usecase (in real web service is call is used via WebClient, but this works too):
Problem with this code, is that Hystrix does not count successful events. This cause incorrect metric, and cause to circuit never to closed.
I have look deeper and found possible root cause.
In
Mono.from(Publisher)
called inHystrixCommands.toMono()
, it createsreactor.core.publisher.MonoFromPublisher
, that subscribereactor.core.publisher.MonoNext.NextSubscriber
. There is invocation of methodonComplete()
inside methodonNext(T)
. This cause the subscription complete and unsubscribe this mono. Because of that parent RxJava Observable (inside hystrix) is unsubscribed and thenonComplete()
call is never fired (and then calculation of successfully event).I have found workaround to use following call:
.toFlux().singleOrEmpty()
instead of call.toMono()
. Following flux -> mono conversion does not callonComplete()
ononNext()
but rather wait for parentonComplete()
propagation.I do not known, if this should be fixed in this project. But at least the workaround may be implemented here.
Note: Additional example, that may be more easily debuged:
Then see
rx.internal.producers.SingleProducer.request(long)
on line 71,c.isUnsubscribed()
return true, then line 75c.onCompleted()
is never reach. When usingFlux.from(RxReactiveStreams.toPublisher(res)).singleOrEmpty()
, the line 75 is reach andc.onCompleted()
is called. Causing hystrix hooks called and properly calculated successful event.Spring version: 2.0.0.RC1 Spring Cloud version: Finchley.M5 Spring Cloud Hystrix version: 2.0.0.M5 Java version: