-
Notifications
You must be signed in to change notification settings - Fork 38.5k
WebClient subscribing twice #23365
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I wrote a test to reproduce this problem (see 9f7dd9f), but it seems to work fine. Closing this for now, but let us now how we can improve the test to reproduce this issue. |
I'd like to confirm the behaviour reported by Sam (my used version is 5.1.7.RELEASE). |
@gmuth please provide a sample if you'd like us to look further. As you can see above we did try the above snippet, a test was written, but could not reproduce it. |
I am also facing the same issue with spring-webflux 5.2.9.RELEASE and using on spring boot version 2.1.11 and it seems to call the the endpoint twice. Below is the dependencies i am using |
good point I haven't checked. Maybe the onStatus() lambda calls are handled correct triggered by according endpoint calls.
|
Twice calling got fixed by removing the subscribe() i think issue is their with subscribe function. |
I am having similar issue. I have list of Mono waiting response from multiple servers. And collectively block them after I subscribed to each of them individually. And I have to subscribe.
|
You should (almost) never
If you're reading this issue and you're still confused, I'd suggest writing a new question on StackOverflow showing a code snippet and explaining what you're trying to achieve. |
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
We are a team of over 50 developers added to it system cloud architects, ans so on ... and we see in the log of SMS server receiving multiple request from the same webclient. We have verified it step by step enabling log on concurrent jakarta jdk21.0.6, (with only Weflux 3.3.4 reactive multiple projects API REST), before with tomcat and now with netty component and in the SMS server log receive multiple requests! We have analyzed multiple time this case and finally we solved it using in webclient: More details on our solution that works fine here in stackoverflow to force mono request from webclient in webflux versus SMS service for this scenario. Using a single thread and get response in async when receive response. I'm not joking webclient in reactive with tomcat or netty (we are migrated in netty) send more request I suppose it is done to respect reactive manifesto in webflux. I'm sure about what I wrote before. |
Other question, why with retrieve it doesn't work and in exchange it works fine. However on the other hand the exchange() method hands you the ClientResponse object itself along with the response status and headers. With exchange method you get fine grained control over your response objects and a better way to handle the response object and the exceptions. If you just want to consume some api go with retrieve(). If you want a better control over your response objects, headers and exceptions, go with exchange()." or other definition:"According to spring Webclient api documentation the difference between the two is that exchange retrieve in addition to the body other http response information like headers and status, while retrieve only returns body information. So If you only need the body information you should use retrieve, because it is a shortcut for exchange and then get the body, but if you need other information like http status you must use exchange." Thanks for your reply. |
Please see the real situation of Baeldung site |
@skyblackhawk This looks very odd. We never managed to reproduce this case so if you can provide a minimal sample application (for example with a client sending requests to httpbin.org), I'd be happy to look into it. Right now I think this might be an invalid combination of calling "block" within a reactive controller method. I'm not sure why things are executed twice though in that case. Again, a minimal sample would be useful to explain things. I think the executors and retrieve vs exchange are red herrings at this stage and probably hiding the real problem. Note: I don't think it's related to rate limiting either. |
This problem we have seen happen for some critical servers that receive a lot of request on its API REST not reactive like this external service not reactive API REST smsSender on external server. My hypothesis is that when arrive datagram of http to the SMS server, it not reply immediatly by handshake and to respect reactive manifesto webclient try to do another request by a new thread. SMS Server of external service is on Azure Cloud and we are on GCP, we using an intermediate server in GCP to redirect call and get response (but it's trasparent to Webflux webclient it). The solution before posted by me and developed by our teams avoid multiple request to send multiple SMS to the customer and it works fine. We are super sure that solution fix the problem and send only one SMS to the customer without that solution SMS server always send two SMS to the customer and it isn't very nice for an OTP SMS. |
This behavior is definitely not part of the reactive streams behavior and should not happen. If the application uses a
It looks like there is a problem in |
We don't use I'm done working. |
WebFlux is actually my favorite framework, you have created a really excellent concurrent multi-threaded framework. Give compliments to all the guys in the team who worked on it, they really deserve it, maybe we who use it do not often say it to all of you, but share these compliments from me too. You all have developed a serious framework that in my opinion will explode in artificial intelligence, (Are you working on a Springboot WebFlux module for AI?) to reduce electricity consumption and with an eye on the environment that we are literally destroying for the sake of future generations. |
@skyblackhawk thanks for the kind words, this means a lot! |
Expected behavior
Only hit
reactor.netty.channel.FluxReceive#startReceiver
onceActual behavior
Hits twice, where second time throws silently the
"Only one connection receive subscriber allowed."
In production, sometimes this exception is reported from
reactor.core.publisher.Operators : Operator called default onErrorDropped ...
.Locally I could only see this exception at the point of throwing inside
FluxReceive#startReceiver
with a debugger. Later inreactor.core.publisher.MonoFlatMap.FlatMapMain#onError
it wasdone = false
, so the exception was never shown anywhere.Steps to reproduce
My calling code is the following:
the logs:
Reactor Core version
org.springframework:spring-webflux:5.1.6.RELEASE
JVM version (e.g.
java -version
)openjdk version "11.0.1" 2018-10-16
========
The workaround for me is using an ExchangeFilterFunction https://stackoverflow.com/a/48984852/6166627 instead of
onStatus
. With this approach, I only hit the start receiver once with a debugger. Hopefully, it's gonna fix itself.Anyway, this ERROR log seems to not affect anything actually, the code still throws MyException
originally posted in reactor but it's off-topic there reactor/reactor-core#1747
Similar: #22096 #22284
The text was updated successfully, but these errors were encountered: