Connection Closure

7 min read

7 min read

7 min read

7 min read

7 min read

7 min read

7 min read

7 min read

7 min read

An Ice communicator creates, reuses and eventually closes outgoing connections, while an object adapter accepts and eventually closes incoming connections.

A connection closure can be either graceful or abortive. A graceful close requires coordination with the peer, and therefore can take some time, while an abort is immediate.

The timeouts on this page are Ice.Connection.* properties: Ice.Connection.Client.* configures outgoing connections, and adapter.Connection.* configures the incoming connections of an object adapter, with Ice.Connection.Server.* as defaults. The idle check and the inactivity check do not apply to UDP connections.

Once a connection is established, Ice aborts a connection when a read or write on this connections fails.

But what happens when there is no read or write activity on a connection? For example, an object adapter may be listening for requests from a dead client, but there is nothing to read or write from that client (remember, it’s dead). Likewise, a client may send a request to a server and not hear back from this server for while–it could because the request dispatch takes a while, or because the connection dropped.

Ice provides a simple mechanism to monitor connection health: the idle check. If a connection waits to read a byte for over IdleTimeout, the connection is considered idle and aborted.

The default idle timeout is 60 seconds. Setting IdleTimeout to 0 disables the idle check and the heartbeats.

This idle check requires regular “write” activity from a healthy peer, which Ice provides: when the application does not write anything to a connection for half the idle timeout, Ice sends (writes) a heartbeat message to clear the idle check in the peer. A heartbeat is a oneway, unacknowledged, ValidateConnection message.

In order to operate properly, the idle check requires the same IdleTimeout configuration on both sides of the connection. You should assign the same idle timeout to all your clients and servers, and typically keep the default.

A connection that reached its MaxDispatches limit stops reading and suspends its idle check until the number of dispatches falls below this limit. A connection that nobody reads because all the threads of its thread pool are busy does not suspend it: when the starvation lasts longer than the idle timeout, the idle check aborts the connection.

A client can establish a connection to a server, send one request to this server, and never use this connection again. While a connection doesn’t consume much resources, we’d rather clean it up and not to keep this connection open until either the client or server shuts down.

This is where the “inactivity check” comes in. A connection that remains inactive for InactivityTimeout is automatically closed. This timeout only takes into account application-level activities: heartbeats don’t count. The default inactivity timeout is 300 seconds (5 minutes).

Setting InactivityTimeout to 0 disables the inactivity check; disableInactivityCheck disables it for one connection.

When a client or server closes a connection gracefully, it sends a CloseConnection message to the peer, to notify the peer of the pending connection closure.

The client or server that sends CloseConnection guarantees that:

  • it won’t send additional requests over the connection; and
  • it has sent responses to all requests it accepted over the connection; any other request sent by the peer will be discarded and not processed in any way (meaning the peer can safely retry them)

Then, it waits for the peer to acknowledge this CloseConnection message. This acknowledgment can take two forms:

  • a CloseConnection message from the peer, which occurs when both sides initiate a graceful connection closure at about the same time; or
  • the closure of the underlying transport connection

The peer closes the connection when it receives the CloseConnection message, without waiting for its own dispatches to complete.

This process can take some time. If the graceful closure exceeds the configured CloseTimeout, the connection is aborted.

Ice closes a connection gracefully when:

Ice also closes connections when:

  • an object adapter is deactivated, including when you shut down its communicator: Ice closes its incoming connections; or
  • a communicator is destroyed: Ice closes all its connections.

When it deactivates an object adapter or destroys a communicator, Ice waits for the dispatches in progress to complete, but not for the outstanding invocations, which fail with ObjectAdapterDeactivatedException or CommunicatorDestroyedException.

An application can close a connection it obtained from a proxy with ice_getConnection or from the Current object of a dispatch: close closes the connection gracefully, once its outstanding invocations have completed, and abort aborts it. See ConnectionConnectionConnectionConnectionConnectionConnectionConnection in the API reference.