wso2wso2-api-managerconnection-timeoutballerina

Ballerina timing out after 1 minute


I had a ballerina API and there is an API call which I am making, sadly the API's is taking more than one minute to respond and ballerina is timing out after the 1 minute. I try to increase the ballerina time out as much as possible but still after one minute the API will throw timeout. Is there any fix for this?

final http:Client organization_CustomerMs = check new (organization_url,
    secureSocket = {
        enable: false
    },
    timeout = 800000
);

Idle timeout triggered before initiating inbound is the exception I am getting.


Solution

  • I believe you have a passthrough service like the below:

    import ballerina/http;
    
    final http:Client clientEP = check new("http://localhost:9090");
    
    service /api on new http:Listener(9091) {
    
        resource function get greeting() returns string|error {
            return clientEP->/greeting;
        }
    }
    

    If you are receiving a 500 status code response with the below error message:

    Idle timeout triggered before initiating inbound response
    

    then it implies that the client used inside the service gets timeout before receiving the response.

    To solve this, you have to increase the timeout in the client configuration as you mentioned:

    // Default timeout is 60s
    final http:Client clientEP = check new("http://localhost:9090", timeout = 100);
    

    But even if you increase this, you will experience a 408 - Request Timeout response with the following error message:

    Idle timeout triggered before initiating outbound response
    

    This is because the server has a default 60s timeout and it gets timeout before receiving the response from the client. So we have to increase the listener timeout on the server side as well:

    import ballerina/http;
    
    final http:Client clientEP = check new("http://localhost:9090", timeout = 100);
    
    service /api on new http:Listener(9091, timeout = 100) {
    
        resource function get greeting() returns string|error {
            return clientEP->/greeting;
        }
    }