micronaut-projects / micronaut-core

Micronaut Application Framework
http://micronaut.io
Apache License 2.0
6.07k stars 1.07k forks source link

Connections will not closed even though header sent to close explicitly #2088

Closed SamathaUppula closed 5 years ago

SamathaUppula commented 5 years ago

Steps to Reproduce:

  1. Create any micronaut application
  2. Try to connect any api endpoint by using micronat http client
  3. Send a header in the request "connection:close"

    Expected Behaviour:

Connection should be closed after getting the response.

Actual Behaviour:

Connection will never get closed and becomes a persistence connection.

Issue description: This is the code in RoutingInBoundHandler

// default Connection header if not set explicitly


            boolean expectKeepAlive = nettyResponse.protocolVersion().isKeepAliveDefault() || httpRequest.getHeaders().isKeepAlive();
            HttpStatus status = nettyHttpResponse.status();
            if (!expectKeepAlive || status.getCode() > 299) {
                nettyHeaders.add(HttpHeaderNames.CONNECTION, HttpHeaderValues.CLOSE);
            } else {
                nettyHeaders.add(HttpHeaderNames.CONNECTION, HttpHeaderValues.KEEP_ALIVE);
            }
        }```

For HTTP_1_0 isKeepAliveDefault is false but for HTTP_1_1 isKeepAliveDefault is true. According to micronaut gitter discussion HTTP_1_1 is in use so isKeepAliveDefault is always true which is not letting the connection to close.

https://gitter.im/micronautfw/questions
jameskleeh commented 5 years ago

What should happen when both the request and response contain the header and they are different?

jameskleeh commented 5 years ago

@SamathaUppula Are you using a client with a connection pool? Can you include a sample of how the client is being created and the request sent?

jameskleeh commented 5 years ago

Closed due to a lack of feedback