---
title: "Glacier2 Session Management"
url: https://docs.zeroc.com/ice/3.8/services/glacier2/glacier2-session-management
docs_index: https://docs.zeroc.com/llms.txt
---

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

# Glacier2 Session Management

A Glacier2 router requires a client to [create a session](https://docs.zeroc.com/ice/3.8/services/glacier2/getting-started-with-glacier2.md) and forwards requests on behalf of the client until its session ends. A Glacier2 session ends when the connection between the client and the router closes or when the client calls `destroySession` on the router. The server-side application can also end a session by calling `destroy` on the `SessionControl` object that the router passes to the session manager's `create` operation.

You can configure a router to use a custom session manager if your application needs to track the router's session activities. For example, your application may need to acquire resources and initialize the state of back-end services for each new session, and later reclaim those resources when the session ends.

As with the [authentication facility](https://docs.zeroc.com/ice/3.8/services/glacier2/securing-a-glacier2-router.md), Glacier2 provides two session manager interfaces that an application can implement. The `SessionManager` interface receives notifications about sessions that use password authentication, while the `SSLSessionManager` interface is for sessions authenticated using SSL certificates.

## Glacier2 Session Manager Interfaces

The relevant Slice definitions are shown below:

```slice
module Glacier2
{
    exception CannotCreateSessionException
    {
        string reason;
    }

    interface Session
    {
        void destroy();
    }

    interface SessionManager
    {
        Session* create(string userId, SessionControl* control)
            throws CannotCreateSessionException;
    }

    interface SSLSessionManager
    {
        Session* create(SSLInfo info, SessionControl* control)
            throws CannotCreateSessionException;
    }
}
```

When a client [creates a session](https://docs.zeroc.com/ice/3.8/services/glacier2/getting-started-with-glacier2.md) by invoking `createSession` on the `Router` interface, the router validates the client's user name and password and then calls `SessionManager::create`. Similarly, a call to `createSessionFromSecureConnection` causes the router to invoke `SSLSessionManager::create`. The [SSLInfo](https://docs.zeroc.com/ice/3.8/services/glacier2/securing-a-glacier2-router.md) structure provides details about the client's SSL connection. The second argument to the `create` operations is a proxy for a `SessionControl` object, which a session can use to perform [dynamic filtering](https://docs.zeroc.com/ice/3.8/services/glacier2/dynamic-request-filtering-with-glacier2.md).

The `create` operations must return the proxy of a new `Session` object, or raise `CannotCreateSessionException` and provide an appropriate reason. The `Session` proxy returned by `create` is ultimately returned to the client as the result of `createSession` or `createSessionFromSecureConnection`.

Glacier2 invokes the `destroy` operation on a `Session` proxy when the session ends, giving a custom session manager the opportunity to reclaim resources that were acquired for the session during `create`.

> **Note**
>
> Glacier2 does not limit a user to one session: the same user can have several sessions at the same time, for example when a client reconnects before the router has detected the loss of its previous connection. A session manager must therefore handle a `create` call for a user who already has a session.

To configure the router with a custom session manager, define the properties [Glacier2.SessionManager](https://docs.zeroc.com/ice/3.8/property-reference/glacier2-properties.md#glacier2.sessionmanager) or [Glacier2.SSLSessionManager](https://docs.zeroc.com/ice/3.8/property-reference/glacier2-properties.md#glacier2.sslsessionmanager) with the proxies of the session manager objects. If necessary, you can configure a router with proxies for both types of session managers. If a session manager proxy is not supplied, the call to `createSession` or `createSessionFromSecureConnection` always returns a null proxy.

The router attempts to contact the configured session manager at startup. If the object is unreachable, the router logs a warning message but continues its normal operation. The router does not contact the session manager again until it needs to invoke an operation on the object. For example, when a client asks the router to create a new session, the router makes another attempt to contact the session manager; if the session manager is still unavailable, the router returns `CannotCreateSessionException` to the client.

## Connection Caching for Session Managers

You can distribute the load among multiple session manager objects by configuring the router with a session manager proxy that contains multiple endpoints. Glacier2 disables [connection caching](https://docs.zeroc.com/ice/3.8/runtime/connection-management/connection-establishment.md) on this proxy so that each invocation on a session manager attempts to use a different endpoint.

This behavior achieves a basic form of load balancing without depending on the [replication](https://docs.zeroc.com/ice/3.8/services/icegrid/object-adapter-replication.md) features provided by IceGrid. Be aware that including an invalid endpoint in your session manager proxy, such as the endpoint of a session manager server that is not currently running, can cause router clients to experience delays during session creation.

If your session managers are in an IceGrid replica group, refer to [IceGrid and Glacier2 Integration](https://docs.zeroc.com/ice/3.8/services/glacier2/icegrid-and-glacier2-integration.md) for more information on the router's caching behavior.

## See Also

- [Getting Started with Glacier2](https://docs.zeroc.com/ice/3.8/services/glacier2/getting-started-with-glacier2.md)
- [Securing a Glacier2 Router](https://docs.zeroc.com/ice/3.8/services/glacier2/securing-a-glacier2-router.md)
- [Dynamic Request Filtering with Glacier2](https://docs.zeroc.com/ice/3.8/services/glacier2/dynamic-request-filtering-with-glacier2.md)
- [IceGrid and Glacier2 Integration](https://docs.zeroc.com/ice/3.8/services/glacier2/icegrid-and-glacier2-integration.md)
- [Object Adapter Replication](https://docs.zeroc.com/ice/3.8/services/icegrid/object-adapter-replication.md)
- [Glacier2.\*](https://docs.zeroc.com/ice/3.8/property-reference/glacier2-properties.md)
