Timeout on synchronous requests inside the Af-Arch


Af-Arch framework support two remote service invocation: synchronous and asynchronous. While asynchronous version doesn't support request timeout because Af-Arch client caller doen't get blocked, synchronous request does support timeouts.

Synchronous requests makes caller to get blocked until the whole request is completed, that is, request is sent marshalling the data, server response process request, makes replies and client unmarshall reply to upper levels where Af-Arch client is waiting blocked for the response.

On this context, it is needed to support a timeout mechanism to avoid infinite waits for reply answer.

How to use synchronous timeout

Synchronous request timeouts are transparetly implemented so, client caller doesn't need to perform any especial operation to implement it.

However, timeout request can be configured to make timeout values to be close to Af-Arch programmer desire. By default, Af-Arch comes with a timeout set to 10 seconds. In case to be need to change it the following function can be used:

     // sets a request timeout for 15 seconds
     afdal_sync_set_timeout (15000000);

In fact, this function sets an environment variable used across Af-Arch to define current timeout: AF_SYNC_TIMEOUT. This allows to configure request timeouts from outside the Af-Arch client code using environment variables syntax:

     bash:~$ AF_SYNC_TIMEOUT=15000000 my-af-arch-client

Remember AF_SYNC_TIMEOUT also expect timeout value in milliseconds.

You can check the following example which makes use of Af-Arch synchronous request timeouts: Synchrouns timeout server and client test.