Invocation Timeouts

3 min read

3 min read

3 min read

4 min read

3 min read

3 min read

3 min read

3 min read

4 min read

Invocation timeouts let an application specify the maximum amount of time it's willing to wait for invocations to complete. If the timeout expires, the application receives InvocationTimeoutException as the result of an invocation. The proxy starts the timer for the invocation timeout after the marshaling of the request parameters and before its starts any network activity (connection establishment and sending of the request over the network connection). For a two-way invocation, it stops the timer as soon as the response is received from the server and before the response payload is unmarshaled. For a one-way invocation, it stops the timer as soon as the request is sent.

The property Ice.Default.InvocationTimeout establishes the default invocation timeout value for proxies. This property has a default value of -1, which means invocations do not time out by default.

Consider this setting:

Properties
Ice.Default.InvocationTimeout=5000 # in milliseconds

This configuration causes all invocations to time out if they do not complete within five seconds. Generally speaking however, it's unlikely that a single timeout value will be appropriate for all of the operations that an application invokes. It's more common for applications to configure invocation timeouts on a per-proxy basis, as we describe in the next section.

You have a couple of options for configuring the invocation timeout of a proxy:

  • Use a proxy property
  • Call ice_invocationTimeout

Assuming you've defined a configuration property containing a proxy that your application reads using propertyToProxy, you can configure an invocation timeout as follows:

Properties
# Assumes the application calls propertyToProxy("GreeterProxy")
GreeterProxy=greeter:tcp -h localhost -p 4061
GreeterProxy.InvocationTimeout=2500 # milliseconds

The InvocationTimeout proxy property specifies the invocation timeout that will be used for all invocations made via the proxy returned by propertyToProxy.

To configure an invocation timeout at runtime, use the ice_invocationTimeout proxy factory method to obtain a new proxy with the desired timeout:

C++
VisitorCenter::GreeterPrx greeter{communicator, "greeter:tcp -h localhost -p 4061"};
greeter = greeter.ice_invocationTimeout(2500ms);
C#
var greeter = GreeterPrxHelper.createProxy(
communicator,
"greeter:tcp -h localhost -p 4061");
greeter = GreeterPrxHelper.uncheckedCast(
greeter.ice_invocationTimeout(TimeSpan.FromMilliseconds(2500)));
Java
var greeter = GreeterPrx.createProxy(communicator, "greeter:tcp -h localhost -p 4061");
greeter = greeter.ice_invocationTimeout(Duration.ofMillis(2500));
JavaScript
var greeter = new VisitorCenter.GreeterPrx(
communicator,
"greeter:tcp -h localhost -p 4061");
greeter = greeter.ice_invocationTimeout(2500);
MATLAB
greeter = GreeterPrx(communicator, 'greeter:tcp -h localhost -p 4061');
greeter = greeter.ice_invocationTimeout(2500);
PHP
$greeter = GreeterPrxHelper::createProxy(
$communicator,
'greeter:tcp -h localhost -p 4061');
$greeter = $greeter->ice_invocationTimeout(2500);
Python
greeter = GreeterPrx(communicator, "greeter:tcp -h localhost -p 4061")
greeter = greeter.ice_invocationTimeout(2500)
Ruby
greeter = GreeterPrx.new(communicator, "greeter:tcp -h localhost -p 4061")
greeter = greeter.ice_invocationTimeout(2500)
Swift
var greeter = try makeProxy(
communicator: communicator,
proxyString: "greeter:tcp -h localhost -p 4061",
type: GreeterPrx.self)
greeter = greeter.ice_invocationTimeout(2500)

An application that configures invocation timeouts must be prepared to catch InvocationTimeoutException:

C++
try
{
auto greeting = greeter.greet("Alice");
...
}
catch (const Ice::InvocationTimeoutException&)
{
cerr << "invocation timed out" << endl;
}
C#
try
{
greeting = await greeter.GreetAsync("alice");
...
}
catch (Ice.InvocationTimeoutException exception)
{
Console.WriteLine("invocation timed out");
}
Java
try {
greeting = greeter.greet("alice");
...
} catch (InvocationTimeoutException exception) {
System.out.println("invocation timed out");
}
JavaScript
try {
greeting = await greeter.greet("alice");
...
} catch (exception) {
if (exception instanceof Ice.InvocationTimeoutException) {
console.log("invocation timed out");
} else {
throw exception;
}
}
MATLAB
try
greeting = greeter.greet('alice');
...
catch ex
if isa(ex, 'Ice.InvocationTimeoutException')
fprintf('invocation timed out\n');
else
rethrow(ex);
end
end
PHP
try {
$greeting = $greeter->greet("alice");
...
} catch (Ice\InvocationTimeoutException $exception) {
echo "invocation timed out\n";
}
Python
try:
greeting = await greeter.greetAsync("alice")
...
except Ice.InvocationTimeoutException as exception:
print("invocation timed out")
Ruby
begin
greeting = greeter.greet("alice")
...
rescue Ice::InvocationTimeoutException => exception
puts "invocation timed out"
end
Swift
do {
greeting = try await greeter.greet("alice")
...
} catch let error as Ice.InvocationTimeoutException {
print("invocation timed out")
}

The effects of an invocation timeout are limited to the client; no indication is sent to the server, which may still be busy dispatching the request. The Ice runtime in the client ignores a response to this request if the server eventually sends one.