Infinite Subscriptions happening on client call #12183
Replies: 2 comments
-
|
@graemerocher @sdelamo could you please have a check and see if this has something to do with the upgrade ? |
Beta Was this translation helpful? Give feedback.
-
Root Cause1. Reactive Streams subscription behavior changedIn Micronaut 4.x, the HTTP client implementation changed from RxJava2 to Reactive Streams (Project Reactor behind the scenes, depending on your setup). The 2. Error handling in reactive chainsWhen you return an error status ( 3. Kubernetes environment differencesIn K8s, things that trigger the issue but not locally:
4. Micronaut 4.x default retry behaviorMicronaut 4.x introduced more aggressive client retry defaults for certain error conditions (e.g., connection errors, certain HTTP status codes). What you're seeing might be an automatic retry on non-2xx responses. SolutionsSolution 1: Cache the reactive stream (Recommended)Use import io.reactivex.Single;
import io.micronaut.http.HttpResponse;
import io.micronaut.http.HttpStatus;
public Single<HttpResponse<SampleResponse>> checkDirectCall(SampleRequest sampleRequest) {
return sampleClientCall()
.cache() // ← Prevents multiple subscriptions
.map(clientResponse -> HttpResponse.status(HttpStatus.INTERNAL_SERVER_ERROR).body(new SampleResponse()));
}Solution 2: Use
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
We upgraded from micronaut 3.7.3 to 4.7.9.
public Single<HttpResponse<SampleResponse>> checkDirectCall(SampleRequest sampleRequest) { return sampleClientCall() .map(clientResponse-> HttpResponse.status(INTERNAL_SERVER_ERROR).body(new SampleResponse())); }The sampleClientCall() client call is getting invoked multiple times sometimes. We were not able to reproduce issue locally. It happens when
we deploye the service to K8s.
When we set the status to OK, we are not facing the issue.
The same code is working as expected in 3.7.3
Beta Was this translation helpful? Give feedback.
All reactions