diff --git a/src/main/java/io/vertx/core/http/impl/Http2ClientConnection.java b/src/main/java/io/vertx/core/http/impl/Http2ClientConnection.java index 8539b784b92..c3dc2287b00 100644 --- a/src/main/java/io/vertx/core/http/impl/Http2ClientConnection.java +++ b/src/main/java/io/vertx/core/http/impl/Http2ClientConnection.java @@ -242,14 +242,11 @@ static abstract class Stream extends VertxHttp2Stream { protected Handler exceptionHandler; protected Handler pushHandler; protected Handler closeHandler; - protected long writeWindow; - protected final long windowSize; Stream(Http2ClientConnection conn, ContextInternal context, boolean push) { super(conn, context); this.push = push; - this.windowSize = conn.getWindowSize(); } void onContinue() { @@ -450,8 +447,8 @@ public boolean writeQueueFull() { } @Override - public synchronized boolean isNotWritable() { - return writeWindow > windowSize; + public boolean isNotWritable() { + return !messageQueue.isWritable(); } @Override @@ -510,6 +507,10 @@ void handleReset(long errorCode) { @Override void handleWriteQueueDrained() { + Handler handler = drainHandler; + if (handler != null) { + context.dispatch(null, handler); + } } @Override @@ -634,29 +635,7 @@ private void createStream(HttpRequestHead head, Http2Headers headers) throws Htt public Future writeBuffer(ByteBuf buf, boolean end) { Promise promise = context.promise(); writeData(buf, end, promise); - Future fut = promise.future(); - if (buf != null) { - int size = buf.readableBytes(); - synchronized (this) { - writeWindow += size; - } - fut = fut.andThen(ar -> { - Handler drainHandler; - synchronized (this) { - boolean full = writeWindow > windowSize; - writeWindow -= size; - if (full && writeWindow <= windowSize) { - drainHandler = this.drainHandler; - } else { - drainHandler = null; - } - } - if (drainHandler != null) { - drainHandler.handle(null); - } - }); - } - return fut; + return promise.future(); } @Override