Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9334a56

Browse files
committed
Don't automatically start requesting on subscribe
Motivation:HandlerSubscriber automatically starts requests when callingonSubscribe.But when a publisher subscribes, RxJava automatically requests theSubscription if there are some pending requests.When such race condition happen, we end up with 2 threads (calling andevent loop) competing for requesting the Subscription. This results isout of order published messages.Modification:Make HandlerSubscriber#onSubscribe noop and actually delay it to afterPublisher has subscribed.Result:No more out of order messages.
1 parent8c27b67 commit9334a56

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

‎client/src/main/java/org/asynchttpclient/netty/request/body/NettyReactiveStreamsBody.java‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ public void write(Channel channel, NettyResponseFuture<?> future) throws IOExcep
5858
NettySubscribersubscriber =newNettySubscriber(channel,future);
5959
channel.pipeline().addLast(NAME_IN_CHANNEL_PIPELINE,subscriber);
6060
publisher.subscribe(newSubscriberAdapter(subscriber));
61+
subscriber.delayedStart();
6162
}
6263
}
6364

@@ -108,6 +109,17 @@ protected void complete() {
108109
.addListener(future ->removeFromPipeline()));
109110
}
110111

112+
privatevolatileSubscriptiondeferredSubscription;
113+
114+
@Override
115+
publicvoidonSubscribe(Subscriptionsubscription) {
116+
deferredSubscription =subscription;
117+
}
118+
119+
publicvoiddelayedStart() {
120+
super.onSubscribe(deferredSubscription);
121+
}
122+
111123
@Override
112124
protectedvoiderror(Throwableerror) {
113125
if (error ==null)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp