Skip to content

Commit d8efdd8

Browse files
committed
Fix incorrect Http2UpgradeClientConnection write.
Motivation: Http2UpgradeClientConnection#write has two issues - the returned promise/future is not completed by the delegate write - the event SEND_BUFFERED_MESSAGES_EVENT can end the http request before all chunks have been written Changes: - return the actual future of the delegate write operation - delay SEND_BUFFERED_MESSAGES_EVENT when the last chunk has been written
1 parent fb51023 commit d8efdd8

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

vertx-core/src/main/java/io/vertx/core/http/impl/Http2UpgradeClientConnection.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -696,18 +696,26 @@ public boolean writeQueueFull() {
696696

697697
@Override
698698
public Future<Void> writeBuffer(ByteBuf buf, boolean end) {
699-
Promise<Void> promise = upgradingStream.getContext().promise();
700699
EventExecutor exec = upgradingConnection.channelHandlerContext().executor();
701700
if (exec.inEventLoop()) {
702-
upgradingStream.writeBuffer(buf, end);
701+
Future<Void> future = upgradingStream.writeBuffer(buf, end);
703702
if (end) {
704703
ChannelPipeline pipeline = upgradingConnection.channelHandlerContext().pipeline();
705-
pipeline.fireUserEventTriggered(SEND_BUFFERED_MESSAGES);
704+
future = future.andThen(ar -> {
705+
if (ar.succeeded()) {
706+
pipeline.fireUserEventTriggered(SEND_BUFFERED_MESSAGES);
707+
}
708+
});
706709
}
710+
return future;
707711
} else {
708-
exec.execute(() -> writeBuffer(buf, end));
712+
Promise<Void> promise = upgradingStream.getContext().promise();
713+
exec.execute(() -> {
714+
Future<Void> future = writeBuffer(buf, end);
715+
future.onComplete(promise);
716+
});
717+
return promise.future();
709718
}
710-
return promise.future();
711719
}
712720

713721
@Override

0 commit comments

Comments
 (0)