What problem does it solve?
Prevents session-related bugs by teaching how Serverpod sessions are created, used, and closed so you avoid leaked resources and “session closed” errors.
Core Features & Use Cases
- Session types and lifetimes: Understand which session is created for method calls, web routes, streams, WebSockets, future calls, and manual internal sessions.
- Safe manual session management: Learn how to close
InternalSession reliably (including why unclosed sessions leak memory and logs).
- Cleanup callbacks and correct timing: Use
addWillCloseListener correctly and avoid capturing request sessions for work that runs after the endpoint returns.
- Use case: When debugging a “StateError: session already closed” caused by a delayed callback (like a timer), apply the guidance to refactor the work into a future call or a fresh internal session.
Quick Start
Ask the assistant to explain which session type you’re using and how to refactor your code so it never uses a session after the endpoint returns.