DynamicSupervisor that manages all active sessions for a single connection.
Each connection has its own SessionSupervisor instance, which dynamically spawns and monitors Session processes. This provides:
- Isolated fault tolerance (a session crash doesn't affect other sessions)
- Dynamic session creation as needed
- Automatic cleanup of terminated sessions
Supervision Strategy
Uses a :one_for_one strategy, meaning if a session crashes, only that
specific session is restarted, not all sessions.
Session Lifecycle
- Connection receives
session/newrequest - Connection calls
start_session/4 - SessionSupervisor spawns a new Session process
- Session registers itself with the Connection
- Session handles messages until terminated
Summary
Functions
Returns a specification to start this module under a supervisor.
Starts a new SessionSupervisor.
Starts a new session under this supervisor.
Functions
Returns a specification to start this module under a supervisor.
See Supervisor.
@spec start_link(keyword()) :: Supervisor.on_start()
Starts a new SessionSupervisor.
Typically started automatically by a Connection process.
@spec start_session(pid(), module(), term(), pid(), String.t() | nil) :: DynamicSupervisor.on_start_child()
Starts a new session under this supervisor.
Parameters
sup- PID of the SessionSupervisorhandler_module- Module implementing the protocol handlerinitial_handler_state- Initial state for the handlertransport_pid- PID of the transport processsession_id- (optional) Use this session_id instead of generating a new one
Returns
{:ok, session_pid} on success, or {:error, reason} on failure.