rschmitt commented on code in PR #547: URL: https://github.com/apache/httpcomponents-core/pull/547#discussion_r2267919218
########## httpcore5/src/main/java/org/apache/hc/core5/http/nio/command/StaleCheckCommand.java: ########## @@ -0,0 +1,58 @@ +/* + * ==================================================================== + * 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.http.nio.command; + +import org.apache.hc.core5.annotation.Internal; +import org.apache.hc.core5.concurrent.FutureCallback; +import org.apache.hc.core5.reactor.Command; +import org.apache.hc.core5.util.Args; + +/** + * Stale check command. + * + * @since 5.4 + */ +@Internal +public final class StaleCheckCommand implements Command { + + private final FutureCallback<Boolean> callback; + + public StaleCheckCommand(final FutureCallback<Boolean> callback) { + this.callback = Args.notNull(callback, "Callback"); + } + + public FutureCallback<Boolean> getCallback() { + return callback; + } + + @Override + public boolean cancel() { + return true; Review Comment: Cancel the callback ########## httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/AbstractHttp1StreamDuplexer.java: ########## @@ -429,6 +433,20 @@ void requestShutdown(final CloseMode closeMode) { ioSession.setEvent(SelectionKey.OP_WRITE); } + void doStalecheck(final FutureCallback<Boolean> callback) throws IOException { + if (!ioSession.isOpen() || connState.compareTo(ConnectionState.ACTIVE) > 0) { + callback.completed(false); + } + final ByteBuffer buffer = ByteBuffer.allocate(0); + final int bytesRead = ioSession.channel().read(buffer); Review Comment: I think this read is actually redundant. `Command` is modeled as a write event, and reads are processed before writes. So if the connection is closed, we'll already know by the time we get here, _provided_ that we include the changes from https://github.com/apache/httpcomponents-core/pull/543. The end result ends up being very similar to the "synchronization barrier" between the event loop and the connection pool that I was talking about in that PR. The internal race condition basically goes away as long as connection reuse is completed through the event loop, which then has a chance to update all the relevant bookkeeping with respect to whatever IO events are pending. -- 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: dev-unsubscr...@hc.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@hc.apache.org For additional commands, e-mail: dev-h...@hc.apache.org