Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure the request counter is updated once when the request is received #3543

Merged
merged 1 commit into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -605,8 +605,9 @@ public Context currentContext() {

@Override
public String asShortText() {
String shortId = this.shortId;
if (shortId == null) {
shortId = initShortId();
this.shortId = shortId = initShortId();
}

return shortId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ protected HttpOperations(HttpOperations<INBOUND, OUTBOUND> replaced) {
protected HttpOperations(Connection connection, ConnectionObserver listener, HttpMessageLogFactory httpMessageLogFactory) {
super(connection, listener);
this.httpMessageLogFactory = httpMessageLogFactory;
if (connection instanceof AtomicLong) {
((AtomicLong) connection).incrementAndGet();
}
}

/**
Expand Down Expand Up @@ -372,7 +375,7 @@ protected final boolean markSentHeaderAndBody(Object... objectsToRelease) {
protected final String initShortId() {
Connection connection = connection();
if (connection instanceof AtomicLong) {
return connection.channel().id().asShortText() + '-' + ((AtomicLong) connection).incrementAndGet();
return connection.channel().id().asShortText() + '-' + ((AtomicLong) connection).get();
}
return super.initShortId();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.BiFunction;
import java.util.function.Function;
Expand Down Expand Up @@ -3129,7 +3130,12 @@ void testRemoveRoutes() {
@ParameterizedTest
@ValueSource(ints = {-1, 1, 2})
void testMaxKeepAliveRequests(int maxKeepAliveRequests) {
HttpServer server = createServer().handle((req, res) -> res.sendString(Mono.just("testMaxKeepAliveRequests")));
AtomicLong requestId = new AtomicLong();
HttpServer server = createServer().handle((req, res) -> {
String id = req.requestId();
requestId.set(Integer.parseInt(id.substring(id.lastIndexOf('-') + 1)));
return res.sendString(Mono.just("testMaxKeepAliveRequests"));
});
assertThat(server.configuration().maxKeepAliveRequests()).isEqualTo(-1);

server = server.maxKeepAliveRequests(maxKeepAliveRequests);
Expand All @@ -3154,17 +3160,17 @@ void testMaxKeepAliveRequests(int maxKeepAliveRequests) {
"testMaxKeepAliveRequests".equals(l.get(1).getT1());

if (maxKeepAliveRequests == -1) {
return result &&
return result && requestId.get() == 2 &&
"persistent".equals(l.get(0).getT2()) &&
"persistent".equals(l.get(1).getT2());
}
else if (maxKeepAliveRequests == 1) {
return result &&
return result && requestId.get() == 1 &&
"close".equals(l.get(0).getT2()) &&
"close".equals(l.get(1).getT2());
}
else if (maxKeepAliveRequests == 2) {
return result &&
return result && requestId.get() == 2 &&
"persistent".equals(l.get(0).getT2()) &&
"close".equals(l.get(1).getT2());
}
Expand Down
Loading