ok2c commented on code in PR #581:
URL:
https://github.com/apache/httpcomponents-core/pull/581#discussion_r2637892374
##########
httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/AbstractH2StreamMultiplexer.java:
##########
@@ -1579,4 +1616,50 @@ public String toString() {
}
+ private void checkStreamTimeouts(final long nowNanos) throws IOException {
+ for (final Iterator<H2Stream> it = streams.iterator(); it.hasNext(); )
{
+ final H2Stream stream = it.next();
+ if (!stream.isActive()) {
+ continue;
+ }
+
+ final Timeout idleTimeout = stream.getIdleTimeout();
+ final Timeout lifetimeTimeout = stream.getLifetimeTimeout();
+ if ((idleTimeout == null || !idleTimeout.isEnabled())
+ && (lifetimeTimeout == null ||
!lifetimeTimeout.isEnabled())) {
+ continue;
+ }
+
+ final long created = stream.getCreatedNanos();
+ final long last = stream.getLastActivityNanos();
+
+ if (idleTimeout != null && idleTimeout.isEnabled()) {
+ final long idleNanos = idleTimeout.toNanoseconds();
+ if (idleNanos > 0 && nowNanos - last > idleNanos) {
+ final int streamId = stream.getId();
+ final H2StreamTimeoutException ex = new
H2StreamTimeoutException(
+ "HTTP/2 stream idle timeout (" + idleTimeout + ")",
+ streamId,
+ idleTimeout,
+ true);
+ stream.localReset(ex, H2Error.CANCEL);
+ continue;
+ }
+ }
+
+ if (lifetimeTimeout != null && lifetimeTimeout.isEnabled()) {
Review Comment:
@arturobernalg What `lifetimeTimeout` could be good for? Why do we need it?
##########
httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/AbstractH2StreamMultiplexer.java:
##########
@@ -412,7 +419,12 @@ private void incrementInputCapacity(
void requestSessionOutput() {
outputRequests.incrementAndGet();
- ioSession.setEvent(SelectionKey.OP_WRITE);
+ try {
Review Comment:
@arturobernalg Same.
##########
httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/AbstractH2StreamMultiplexer.java:
##########
@@ -642,6 +662,7 @@ private void executeRequest(final RequestExecutionCommand
requestExecutionComman
requestExecutionCommand.getExchangeHandler(),
requestExecutionCommand.getPushHandlerFactory(),
requestExecutionCommand.getContext()));
+ initializeStreamTimeouts(stream);
Review Comment:
@arturobernalg This looks wrong. The idea is to let the callback from
`RequestExecutionCommand` decide what is to be done upon stream initialization.
The `StreamControl` should just provide a setter.
##########
httpcore5-h2/src/main/java/org/apache/hc/core5/http2/H2StreamTimeoutException.java:
##########
@@ -0,0 +1,87 @@
+/*
+ * ====================================================================
+ * 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;
+
+import java.net.SocketTimeoutException;
+
+import org.apache.hc.core5.util.Timeout;
+
+/**
+ * {@link java.net.SocketTimeoutException} raised by the HTTP/2 stream
+ * multiplexer when a per-stream timeout elapses.
+ * <p>
+ * This exception is used for timeouts that are scoped to a single HTTP/2
+ * stream rather than the underlying TCP connection, for example:
+ * </p>
+ * <ul>
+ * <li>an idle timeout where no activity has been observed on the stream,
or</li>
+ * <li>a lifetime timeout where the total age of the stream exceeds
+ * the configured limit.</li>
+ * </ul>
+ * <p>
+ * The {@link #isIdleTimeout()} flag can be used to distinguish whether
+ * the timeout was triggered by idleness or by the overall stream lifetime.
+ * The affected stream id and the timeout value are exposed via
+ * {@link #getStreamId()} and {@link #getTimeout()} respectively.
+ * </p>
+ *
+ * @since 5.4
+ */
+public class H2StreamTimeoutException extends SocketTimeoutException {
Review Comment:
@arturobernalg This exception should be a subclass of
`InterruptedIOException` and not `SocketTimeoutException`. This is not a
socket exception.
##########
httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/AbstractH2StreamMultiplexer.java:
##########
@@ -270,7 +272,12 @@ private void commitFrameInternal(final RawFrame frame)
throws IOException {
} else {
outputQueue.addLast(frame);
}
- ioSession.setEvent(SelectionKey.OP_WRITE);
+ try {
Review Comment:
@arturobernalg Is the right place to catch the exception and close the
connections? Why do you think this is needed? We cannot catch
`CancelledKeyException` in each and every method. This is done at the i/o
reactor level.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]