Saturday, February 11, 2017

WSO2 API Manager : Configure timeouts

A server connection timeout error does little to tell you what went wrong or why the error happened: it just identifies that the error occurred. Since Endpoints send the message out, they can encounter various transport errors. For example connection may time out, or connection may be closed by the actual service and even an Internet connection can be at fault.

Today we are talking how we can deal with Connection timed out errors in APIM.

Use-Case


Suppose a user is having a backend which is taking more than 5 -6 minutes to give a response back, The API that is waiting for backend response and will make timeout error after waiting 30000ms since exceeding of default value of the endpoint timeout by thinking connection may be closed by the actual service. 

We can get over with this kind of situations by doing manual configurations inside the apim configurations.        



There are 3 types of timeouts in API Manager

  • Endpoint timeout/connection timeout in per API level
  • Socket timeout
  • Global timeout


  1. When it’s needed to Set timeout in API level per each API you can go for following method. You can set the timeout value through management console for the API you want to increase the time out for 6 min.(60000miliseconds * 6 = 360000 ms)Please note that this configuration will override the "synapse.global_timeout_interval" value for that API

  2. <api name="admin--Emailverification" context="/phoneverify" version="1.0.0" version-type="url">
     <send>
       <endpoint name="admin--Emailverification_APIproductionEndpoint_0">
          <http uri-template="  http://ws.cdyne.com/emailverify/emailverify.asmx" />
          <timeout>
             <duration> 360000 </duration>
             <responseAction>fault</responseAction>
          </timeout>
       </endpoint>
    </send>
    </api>
    



  3. Socket timeout defined in the passthru-http.properties (APIMHOME\repository\conf\passthru-http.properties)

  4. http.socket.timeout=60000000
  • But According to the scenario we are talking here you can see endpoint timeout > http.socket.timeout since our default socket.timeout is 60000ms ..


  •  It's important If the endpoint timeout > http.socket.timeout, whatever value we set in endpoint timeout is not getting applied, but the value of http.socket.timeout will be used in request timeouts. Basically, when endpoint timeout > http.socket.timeout, the engine will timeout the endpoint after http.socket.timeout, irrespective of the timeout action or timeout value we configured in endpoint level.

  • So it is a must to configure http.socket timeout to higher value than the synapse global timeout or endpoint timeout values.

So I am increasing the socket timeout value here, adhering to the above condition ("http.socket.timeout=60000000" )

3. Global timeout defined in synapse.properties (\repository\conf\synapse.properties)This can’t be set per API level but when it’s applied it will affect globally for all API’s 

    synapse.global_timeout_interval=60000000


Note:

If you need any further assistancor have queries regarding the "WSO2 API Manager  : Configure timeouts Do not hesitate to comment below ....

4 comments:

  1. Hi How to set the timeout value through Management console

    ReplyDelete
  2. Hi Shilpa,

    You can change the connection timeout duration values through UI(So there you can make customize timeout values for your apis, when you are about to create them) before go for an detail explanation could you please mention the APIM version that you are using

    ReplyDelete
  3. Hi -- How to setup timeout value at API level for Dynamic Endpoint APIs ?

    ReplyDelete
    Replies
    1. I am using wso2apim-2.6.0. is there way to set timeout through APIM management console ?

      Delete