---
title: "Connection Closure"
url: https://docs.zeroc.com/ice/3.8/runtime/connection-management/connection-closure
docs_index: https://docs.zeroc.com/llms.txt
---

> For an index of every page, see [llms.txt](https://docs.zeroc.com/llms.txt).

# Connection Closure

Parts of this page are for some programming languages only, and name them. For one language's text alone, see [C++](https://docs.zeroc.com/ice/3.8/runtime/connection-management/connection-closure/cpp.md), [C#](https://docs.zeroc.com/ice/3.8/runtime/connection-management/connection-closure/csharp.md), [Java](https://docs.zeroc.com/ice/3.8/runtime/connection-management/connection-closure/java.md), [JavaScript](https://docs.zeroc.com/ice/3.8/runtime/connection-management/connection-closure/js.md), [MATLAB](https://docs.zeroc.com/ice/3.8/runtime/connection-management/connection-closure/matlab.md), [PHP](https://docs.zeroc.com/ice/3.8/runtime/connection-management/connection-closure/php.md), [Python](https://docs.zeroc.com/ice/3.8/runtime/connection-management/connection-closure/python.md), [Ruby](https://docs.zeroc.com/ice/3.8/runtime/connection-management/connection-closure/ruby.md), and [Swift](https://docs.zeroc.com/ice/3.8/runtime/connection-management/connection-closure/swift.md).

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.\*](https://docs.zeroc.com/ice/3.8/property-reference/ice-connection-properties.md) properties: `Ice.Connection.Client.*` configures outgoing connections, and [adapter.Connection.\*](https://docs.zeroc.com/ice/3.8/property-reference/object-adapter-properties.md) 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.

## The Idle Check

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](https://docs.zeroc.com/ice/3.8/property-reference/ice-connection-properties.md), 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.

> **C++, C#, Java, Python, and Swift**
>
> A connection that reached its [MaxDispatches](https://docs.zeroc.com/ice/3.8/property-reference/ice-connection-properties.md) 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.

> **Note**
>
> Interop with previous versions of Ice
>
> Ice 3.7 (and before) did not generate regular write activity on connections by default. If one side of your connection uses Ice 3.7 (or earlier) and the other side uses Ice 3.8 (or newer), the idle check on the 3.8 side can abort a healthy but inactive connection.
>
> To prevent such idle check aborts, configure your Ice 3.7 or 3.6 application to generate regular write activity by setting `Ice.ACM.Heartbeat` to `3`, and making sure `Ice.ACM.Timeout` matches your Ice 3.8 `IdleTimeout`. The default `Ice.ACM.Timeout` is 60 seconds, just like the default `IdleTimeout`.
>
> If you cannot reconfigure your older Ice application, you can disable the idle check on the 3.8 side by setting [EnableIdleCheck](https://docs.zeroc.com/ice/3.8/property-reference/ice-connection-properties.md) to `0`.

## The Inactivity Check

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](https://docs.zeroc.com/ice/3.8/property-reference/ice-connection-properties.md) 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.

> **Warning**
>
> A connection that is inactive is a healthy, but unused, connection. The graceful closure of an inactive connection is an innocuous event.

## Graceful Connection Closure

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](https://docs.zeroc.com/ice/3.8/property-reference/ice-connection-properties.md), the connection is aborted.

Ice closes a connection gracefully when:

- the application closes it with `close`, as described [below](#closing-a-connection-from-the-application); or
- the [inactivity check](#the-inactivity-check) finds it inactive.

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`.

## Closing a Connection from the Application

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 Connection ([C++](https://code.zeroc.com/ice/3.8/api/cpp/classIce_1_1Connection.html), [C#](https://code.zeroc.com/ice/3.8/api/csharp/api/Ice.Connection.html), [Java](https://code.zeroc.com/ice/3.8/api/java/com.zeroc.ice/com/zeroc/Ice/Connection.html), [JavaScript](https://code.zeroc.com/ice/3.8/api/javascript/Ice/Connection.html), [Python](https://code.zeroc.com/ice/3.8/api/python/Ice.Connection.html), and [Swift](https://code.zeroc.com/ice/3.8/api/swift/documentation/ice/connection)) in the API reference.

## See Also

- [Protocol Messages](https://docs.zeroc.com/ice/3.8/protocol/protocol-messages.md)
- [Connection Establishment](https://docs.zeroc.com/ice/3.8/runtime/connection-management/connection-establishment.md)
- [Oneway Invocations](https://docs.zeroc.com/ice/3.8/runtime/invocation/invocation-mode/oneway-invocations.md)
- [Automatic Retries](https://docs.zeroc.com/ice/3.8/runtime/invocation/automatic-retries.md)
