managing-client-lifecycle

Orchestrate PrismaClient shutdown to prevent database connection leaks.

Updated Nov 21, 2025
One-click install
npx skills add https://github.com/djankies/claude-configs --skill managing-client-lifecycle
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: managing-client-lifecycle
Source: https://github.com/djankies/claude-configs/tree/main/prisma-6/skills/upgrading-to-prisma-6
Command: npx skills add https://github.com/djankies/claude-configs --skill managing-client-lifecycle

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill teaches lifecycle management for PrismaClient, including graceful shutdown, disconnect timing, and logging configuration in servered environments and tests.

Core Features & Use Cases

  • Proper shutdown hooks in Express/Fastify and test teardown (afterAll).
  • Configurable logging for development and production.
  • Prevents connection leaks and ensures clean termination.

Quick Start

Integrate a single PrismaClient instance with a server shutdown hook and afterAll teardown in tests.

Frequently Asked Questions about managing-client-lifecycle

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I prevent database connection leaks in PrismaClient?▼

Prevent connection leaks by configuring graceful PrismaClient shutdown with disconnect handlers. Implement shutdown hooks in your server (Express, Fastify) and test teardown (afterAll) to ensure $disconnect() is called before process exit, with a 10-second force-exit timeout to catch missed connections.

What's the best way to handle PrismaClient shutdown in long-running servers?▼

Attach PrismaClient shutdown logic to server lifecycle events. Register a shutdown handler that calls $disconnect() when the server closes, ensuring clean termination of database connections before the process exits.

How do I configure logging for PrismaClient in development and production?▼

Configure environment-based logging in PrismaClient using the log option to set different levels for development and production. This satisfies observability requirements and helps track connection lifecycle events across environments.

Do I need special teardown in test suites when using PrismaClient?▼

Yes. Add afterAll hooks in your test suite to call $disconnect() and ensure database connections close after tests complete, preventing connection leaks and resource exhaustion across test runs.

How does PrismaClient lifecycle management work with serverless functions?▼

Serverless functions require explicit $disconnect() calls before returning, since the runtime may terminate unexpectedly. Implement shutdown logic in your function handler to clean up connections and prevent dangling database sessions.