Skip to content

Commit

Permalink
OAP-227 Close long lived connections when they have handled X requests
Browse files Browse the repository at this point in the history
  • Loading branch information
nofateg authored Feb 6, 2024
1 parent 6de6240 commit 27439af
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,13 @@ public void testCloseConnection() throws IOException {
exchange.responseOk( "ok", Http.ContentType.TEXT_PLAIN );
} );

for( int i = 0; i < 5; i++ ) {
assertThat( Client.DEFAULT.get( "http://localhost:" + testHttpPort + "/test" ).contentString() ).isEqualTo( "ok" );
var client = Client.custom().setMaxConnTotal( 10 ).setMaxConnPerRoute( 10 ).build();

for( int i = 0; i < 101; i++ ) {
assertThat( client.get( "http://localhost:" + testHttpPort + "/test" ).contentString() ).isEqualTo( "ok" );
}

assertThat( ids ).hasSize( 3 );
assertThat( ids ).hasSize( 51 );
assertThat( keepaliveRequestsHandler.requests ).hasSize( 1 );
}
}
Expand Down
3 changes: 1 addition & 2 deletions oap-stdlib-test/src/test/java/oap/io/IoStreamsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,7 @@ public void encodingResolve() {
assertThat( ZSTD.resolve( Paths.get( "/x/a.txt.zst" ) ) ).isEqualTo( Paths.get( "/x/a.txt.zst" ) );
}

@Test
@SneakyThrows
@Test( enabled = false )
public void compressionLevel() {
List<List<String>> sets = new ArrayList<>();
Random random = new Random();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import io.undertow.server.HttpHandler;
import io.undertow.server.HttpServerExchange;
import io.undertow.server.ServerConnection;
import io.undertow.util.Headers;
import oap.http.server.nio.AbstractNioHandler;

import java.util.concurrent.ConcurrentHashMap;
Expand Down Expand Up @@ -32,6 +33,9 @@ public void handleRequest( HttpServerExchange exchange ) throws Exception {
long requests = count.incrementAndGet();

try {
if( requests >= keepaliveRequests ) {
exchange.getResponseHeaders().put( Headers.CONNECTION, "close" );
}
httpHandler.handleRequest( exchange );
} finally {
if( requests >= keepaliveRequests ) {
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
</repositories>

<properties>
<oap.project.version>21.9.0</oap.project.version>
<oap.project.version>21.9.1</oap.project.version>

<oap.deps.config.version>21.0.0</oap.deps.config.version>
<oap.deps.oap-teamcity.version>21.0.1</oap.deps.oap-teamcity.version>
Expand Down

0 comments on commit 27439af

Please sign in to comment.