ballerina-platform / ballerina-library

The Ballerina Library
https://ballerina.io/learn/api-docs/ballerina/
Apache License 2.0
136 stars 64 forks source link

The IDLE based eviction is not supported for HTTP/2 connections #7309

Open TharmiganK opened 3 weeks ago

TharmiganK commented 3 weeks ago

Description

The HTTP client have the following record to configure the IDLE based connection eviction:

public type PoolConfiguration record {|
    # Max active connections per route(host:port). Default value is -1 which indicates unlimited.
    int maxActiveConnections = maxActiveConnections;
    # Maximum number of idle connections allowed per pool.
    int maxIdleConnections = maxIdleConnections;
    # Maximum amount of time (in seconds), the client should wait for an idle connection before it sends an error when the pool is exhausted
    decimal waitTime = waitTime;
    ...
    # Minimum evictable time for an idle connection in seconds. Default value is 5 minutes
    decimal minEvictableIdleTime = minEvictableIdleTime;
    # Time between eviction runs in seconds. Default value is 30 seconds
    decimal timeBetweenEvictionRuns = timeBetweenEvictionRuns;
    ...
|};

But these options are not applied for the HTTP/2 connections. Currently HTTP/2 connections only support STALE based eviction(based on the GO_AWAY frames).

Steps to Reproduce

Service:

import ballerina/http;

service /app on new http:Listener(9090) {

    resource function get api() returns string {
        return "Hello, World!";
    }
}

Client:

import ballerina/http;
import ballerina/lang.runtime;

http:PoolConfiguration poolConfig = {
    minEvictableIdleTime: 5,
    timeBetweenEvictionRuns: 5
};

final http:Client clientEP = check new ("http://localhost:9090/app", poolConfig = poolConfig);

public function main() returns error? {
    http:Response _ = check clientEP->/api;
    runtime:sleep(2);

    http:Response _ = check clientEP->/api;
    runtime:sleep(15);

    // Expects a new connection to be made since the connection is IDLE for the configured time
    http:Response _ = check clientEP->/api;
}

Run the service and client files. Enable trace logs in the client side and you can notice that the same connection is used for the third request as well.

Version

Ballerina SwanLake Update 10(2201.10.0)

Environment Details (with versions)

No response