You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2021/11/10 10:34:47 UTC

[httpcomponents-core] branch HTTPCORE-696 updated (66841cd -> 74269a9)

This is an automated email from the ASF dual-hosted git repository.

olegk pushed a change to branch HTTPCORE-696
in repository https://gitbox.apache.org/repos/asf/httpcomponents-core.git.


 discard 66841cd  H2 stream resource release optimization
 discard e8a44a4  HTTPCORE-696: H2 protocol handler to ensure minimal processing of incoming frames during a graceful shutdown.
     new 3360fc3  HTTPCORE-696: H2 protocol handler to ensure minimal processing of incoming frames during a graceful shutdown.
     new 74269a9  Annotate functional interfaces

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (66841cd)
            \
             N -- N -- N   refs/heads/HTTPCORE-696 (74269a9)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../impl/nio/AbstractH2StreamMultiplexer.java      | 26 +++++++++++-----------
 .../org/apache/hc/core5/function/Callback.java     |  1 +
 .../org/apache/hc/core5/function/Decorator.java    |  1 +
 .../java/org/apache/hc/core5/function/Factory.java |  1 +
 .../org/apache/hc/core5/function/Resolver.java     |  1 +
 .../org/apache/hc/core5/function/Supplier.java     |  1 +
 .../core5/http/io/HttpClientResponseHandler.java   |  1 +
 7 files changed, 19 insertions(+), 13 deletions(-)

[httpcomponents-core] 02/02: Annotate functional interfaces

Posted by ol...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

olegk pushed a commit to branch HTTPCORE-696
in repository https://gitbox.apache.org/repos/asf/httpcomponents-core.git

commit 74269a91829cf1b90650a139359228de00cf685e
Author: Oleg Kalnichevski <ol...@apache.org>
AuthorDate: Sun Nov 7 21:42:49 2021 +0100

    Annotate functional interfaces
---
 httpcore5/src/main/java/org/apache/hc/core5/function/Callback.java       | 1 +
 httpcore5/src/main/java/org/apache/hc/core5/function/Decorator.java      | 1 +
 httpcore5/src/main/java/org/apache/hc/core5/function/Factory.java        | 1 +
 httpcore5/src/main/java/org/apache/hc/core5/function/Resolver.java       | 1 +
 httpcore5/src/main/java/org/apache/hc/core5/function/Supplier.java       | 1 +
 .../main/java/org/apache/hc/core5/http/io/HttpClientResponseHandler.java | 1 +
 6 files changed, 6 insertions(+)

diff --git a/httpcore5/src/main/java/org/apache/hc/core5/function/Callback.java b/httpcore5/src/main/java/org/apache/hc/core5/function/Callback.java
index c92576e..37168d0 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/function/Callback.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/function/Callback.java
@@ -32,6 +32,7 @@ package org.apache.hc.core5.function;
  *
  * @since 5.0
  */
+@FunctionalInterface
 public interface Callback<T> {
 
     void execute(T object);
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/function/Decorator.java b/httpcore5/src/main/java/org/apache/hc/core5/function/Decorator.java
index cdfd699..9390b49 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/function/Decorator.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/function/Decorator.java
@@ -32,6 +32,7 @@ package org.apache.hc.core5.function;
  *
  * @since 5.0
  */
+@FunctionalInterface
 public interface Decorator<T> {
 
     T decorate(T object);
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/function/Factory.java b/httpcore5/src/main/java/org/apache/hc/core5/function/Factory.java
index 6236202..fa55cff 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/function/Factory.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/function/Factory.java
@@ -32,6 +32,7 @@ package org.apache.hc.core5.function;
  *
  * @since 5.0
  */
+@FunctionalInterface
 public interface Factory<P, T> {
 
     T create(P parameter);
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/function/Resolver.java b/httpcore5/src/main/java/org/apache/hc/core5/function/Resolver.java
index 3cb42f4..5a67894 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/function/Resolver.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/function/Resolver.java
@@ -32,6 +32,7 @@ package org.apache.hc.core5.function;
  *
  * @since 5.0
  */
+@FunctionalInterface
 public interface Resolver<I, O> {
 
     O resolve(I object);
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/function/Supplier.java b/httpcore5/src/main/java/org/apache/hc/core5/function/Supplier.java
index b7328a8..3e0b5f1 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/function/Supplier.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/function/Supplier.java
@@ -32,6 +32,7 @@ package org.apache.hc.core5.function;
  *
  * @since 5.0
  */
+@FunctionalInterface
 public interface Supplier<T> {
 
     T get();
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/io/HttpClientResponseHandler.java b/httpcore5/src/main/java/org/apache/hc/core5/http/io/HttpClientResponseHandler.java
index 1db8c98..397ef2e 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/io/HttpClientResponseHandler.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/io/HttpClientResponseHandler.java
@@ -38,6 +38,7 @@ import org.apache.hc.core5.http.HttpException;
  *
  * @since 4.0
  */
+@FunctionalInterface
 public interface HttpClientResponseHandler<T> {
 
     /**

[httpcomponents-core] 01/02: HTTPCORE-696: H2 protocol handler to ensure minimal processing of incoming frames during a graceful shutdown.

Posted by ol...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

olegk pushed a commit to branch HTTPCORE-696
in repository https://gitbox.apache.org/repos/asf/httpcomponents-core.git

commit 3360fc3adcb79a02dcede64ce8b06f6965873b35
Author: Oleg Kalnichevski <ol...@apache.org>
AuthorDate: Wed Nov 10 11:22:54 2021 +0100

    HTTPCORE-696: H2 protocol handler to ensure minimal processing of incoming frames during a graceful shutdown.
---
 .../impl/nio/AbstractH2StreamMultiplexer.java      | 55 ++++++++------
 .../core5/http2/impl/nio/NoopH2StreamHandler.java  | 84 ++++++++++++++++++++++
 2 files changed, 119 insertions(+), 20 deletions(-)

diff --git a/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/AbstractH2StreamMultiplexer.java b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/AbstractH2StreamMultiplexer.java
index 6229b07..e8826c8 100644
--- a/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/AbstractH2StreamMultiplexer.java
+++ b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/AbstractH2StreamMultiplexer.java
@@ -26,7 +26,6 @@
  */
 package org.apache.hc.core5.http2.impl.nio;
 
-import javax.net.ssl.SSLSession;
 import java.io.IOException;
 import java.net.SocketAddress;
 import java.nio.ByteBuffer;
@@ -43,6 +42,8 @@ import java.util.concurrent.ConcurrentLinkedDeque;
 import java.util.concurrent.ConcurrentLinkedQueue;
 import java.util.concurrent.atomic.AtomicInteger;
 
+import javax.net.ssl.SSLSession;
+
 import org.apache.hc.core5.concurrent.Cancellable;
 import org.apache.hc.core5.concurrent.CancellableDependency;
 import org.apache.hc.core5.http.ConnectionClosedException;
@@ -133,6 +134,7 @@ abstract class AbstractH2StreamMultiplexer implements Identifiable, HttpConnecti
 
     private int processedRemoteStreamId;
     private EndpointDetails endpointDetails;
+    private boolean goAwayReceived;
 
     AbstractH2StreamMultiplexer(
             final ProtocolIOSession ioSession,
@@ -503,19 +505,30 @@ abstract class AbstractH2StreamMultiplexer implements Identifiable, HttpConnecti
             processPendingCommands();
         }
         if (connState.compareTo(ConnectionHandshake.GRACEFUL_SHUTDOWN) == 0) {
+            int liveStreams = 0;
             for (final Iterator<Map.Entry<Integer, H2Stream>> it = streamMap.entrySet().iterator(); it.hasNext(); ) {
                 final Map.Entry<Integer, H2Stream> entry = it.next();
                 final H2Stream stream = entry.getValue();
                 if (stream.isLocalClosed() && stream.isRemoteClosed()) {
                     stream.releaseResources();
                     it.remove();
+                } else {
+                    if (idGenerator.isSameSide(stream.getId()) || stream.getId() <= processedRemoteStreamId) {
+                        liveStreams++;
+                    }
                 }
             }
-            if (streamMap.isEmpty()) {
+            if (liveStreams == 0) {
                 connState = ConnectionHandshake.SHUTDOWN;
             }
         }
         if (connState.compareTo(ConnectionHandshake.SHUTDOWN) >= 0) {
+            if (!streamMap.isEmpty()) {
+                for (final H2Stream stream : streamMap.values()) {
+                    stream.releaseResources();
+                }
+                streamMap.clear();
+            }
             ioSession.getLock().lock();
             try {
                 if (outputBuffer.isEmpty() && outputQueue.isEmpty()) {
@@ -722,11 +735,8 @@ abstract class AbstractH2StreamMultiplexer implements Identifiable, HttpConnecti
         if (continuation != null && frameType != FrameType.CONTINUATION) {
             throw new H2ConnectionException(H2Error.PROTOCOL_ERROR, "CONTINUATION frame expected");
         }
-        if (connState.compareTo(ConnectionHandshake.GRACEFUL_SHUTDOWN) >= 0) {
-            if (streamId > processedRemoteStreamId && !idGenerator.isSameSide(streamId)) {
-                // ignore the frame
-                return;
-            }
+        if (goAwayReceived && frameType != FrameType.GOAWAY) {
+            throw new H2ConnectionException(H2Error.PROTOCOL_ERROR, "GOAWAY received");
         }
         switch (frameType) {
             case DATA: {
@@ -757,8 +767,14 @@ abstract class AbstractH2StreamMultiplexer implements Identifiable, HttpConnecti
 
                     final H2StreamChannelImpl channel = new H2StreamChannelImpl(
                             streamId, false, initInputWinSize, initOutputWinSize);
-                    final H2StreamHandler streamHandler = createRemotelyInitiatedStream(
-                            channel, httpProcessor, connMetrics, null);
+                    final H2StreamHandler streamHandler;
+                    if (connState.compareTo(ConnectionHandshake.ACTIVE) <= 0) {
+                        streamHandler = createRemotelyInitiatedStream(channel, httpProcessor, connMetrics, null);
+                    } else {
+                        streamHandler = NoopH2StreamHandler.INSTANCE;
+                        channel.setLocalEndStream();
+                    }
+
                     stream = new H2Stream(channel, streamHandler, true);
                     if (stream.isOutputReady()) {
                         stream.produceOutput();
@@ -939,8 +955,15 @@ abstract class AbstractH2StreamMultiplexer implements Identifiable, HttpConnecti
 
                 final H2StreamChannelImpl channel = new H2StreamChannelImpl(
                         promisedStreamId, false, initInputWinSize, initOutputWinSize);
-                final H2StreamHandler streamHandler = createRemotelyInitiatedStream(
-                        channel, httpProcessor, connMetrics, stream.getPushHandlerFactory());
+                final H2StreamHandler streamHandler;
+                if (connState.compareTo(ConnectionHandshake.ACTIVE) <= 0) {
+                    streamHandler = createRemotelyInitiatedStream(channel, httpProcessor, connMetrics,
+                            stream.getPushHandlerFactory());
+                } else {
+                    streamHandler = NoopH2StreamHandler.INSTANCE;
+                    channel.setLocalEndStream();
+                }
+
                 final H2Stream promisedStream = new H2Stream(channel, streamHandler, true);
                 streamMap.put(promisedStreamId, promisedStream);
 
@@ -963,6 +986,7 @@ abstract class AbstractH2StreamMultiplexer implements Identifiable, HttpConnecti
                 }
                 final int processedLocalStreamId = payload.getInt();
                 final int errorCode = payload.getInt();
+                goAwayReceived = true;
                 if (errorCode == H2Error.NO_ERROR.getCode()) {
                     if (connState.compareTo(ConnectionHandshake.ACTIVE) <= 0) {
                         for (final Iterator<Map.Entry<Integer, H2Stream>> it = streamMap.entrySet().iterator(); it.hasNext(); ) {
@@ -1039,9 +1063,6 @@ abstract class AbstractH2StreamMultiplexer implements Identifiable, HttpConnecti
             if (streamListener != null) {
                 streamListener.onHeaderInput(this, promisedStreamId, headers);
             }
-            if (connState == ConnectionHandshake.GRACEFUL_SHUTDOWN) {
-                throw new H2StreamResetException(H2Error.REFUSED_STREAM, "Stream refused");
-            }
             promisedStream.consumePromise(headers);
         } else {
             continuation.copyPayload(payload);
@@ -1077,9 +1098,6 @@ abstract class AbstractH2StreamMultiplexer implements Identifiable, HttpConnecti
             if (stream.isLocalReset()) {
                 return;
             }
-            if (connState == ConnectionHandshake.GRACEFUL_SHUTDOWN) {
-                throw new H2StreamResetException(H2Error.PROTOCOL_ERROR, "Stream refused");
-            }
             if (frame.isFlagSet(FrameFlag.END_STREAM)) {
                 stream.setRemoteEndStream();
             }
@@ -1101,9 +1119,6 @@ abstract class AbstractH2StreamMultiplexer implements Identifiable, HttpConnecti
             if (streamListener != null) {
                 streamListener.onHeaderInput(this, streamId, headers);
             }
-            if (connState == ConnectionHandshake.GRACEFUL_SHUTDOWN) {
-                throw new H2StreamResetException(H2Error.PROTOCOL_ERROR, "Stream refused");
-            }
             if (stream.isRemoteClosed()) {
                 throw new H2StreamResetException(H2Error.STREAM_CLOSED, "Stream already closed");
             }
diff --git a/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/NoopH2StreamHandler.java b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/NoopH2StreamHandler.java
new file mode 100644
index 0000000..5bbc3d4
--- /dev/null
+++ b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/NoopH2StreamHandler.java
@@ -0,0 +1,84 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+package org.apache.hc.core5.http2.impl.nio;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.util.List;
+
+import org.apache.hc.core5.http.Header;
+import org.apache.hc.core5.http.HttpException;
+import org.apache.hc.core5.http.nio.AsyncPushConsumer;
+import org.apache.hc.core5.http.nio.HandlerFactory;
+
+final class NoopH2StreamHandler implements H2StreamHandler {
+
+    static final NoopH2StreamHandler INSTANCE = new NoopH2StreamHandler();
+
+    @Override
+    public boolean isOutputReady() {
+        return false;
+    }
+
+    @Override
+    public void produceOutput() throws HttpException, IOException {
+    }
+
+    @Override
+    public void consumePromise(final List<Header> headers) throws HttpException, IOException {
+    }
+
+    @Override
+    public void consumeHeader(final List<Header> headers, final boolean endStream) throws HttpException, IOException {
+    }
+
+    @Override
+    public void updateInputCapacity() throws IOException {
+    }
+
+    @Override
+    public void consumeData(final ByteBuffer src, final boolean endStream) throws HttpException, IOException {
+    }
+
+    @Override
+    public HandlerFactory<AsyncPushConsumer> getPushHandlerFactory() {
+        return null;
+    }
+
+    @Override
+    public void failed(final Exception cause) {
+    }
+
+    @Override
+    public void handle(final HttpException ex, final boolean endStream) throws HttpException, IOException {
+    }
+
+    @Override
+    public void releaseResources() {
+    }
+
+}