Memory, File Descriptors, and Connection Pools
A memory leak is often an object that remains reachable, not merely a slow garbage collector. Unbounded caches, retained closures, event listeners, buffers, and queues can retain memory. Monitor heap, resident memory, allocation rate, garbage-collection pauses, and container limits because native memory may not appear in a language heap snapshot.
Sockets, files, and pipes consume file descriptors or similar handles. Leaks can prevent a service from accepting connections even when CPU is low. Connection pools reduce setup cost but multiply across instances: 20 application replicas with 30 database connections each can request 600 connections before administrative or background clients are counted.
Graceful shutdown should stop accepting new traffic, mark the instance unready, drain active requests, finish or release jobs safely, close pools, and exit within the orchestrator's deadline. Test shutdown while requests and jobs are in flight.
- Garbage collection cannot reclaim reachable objects.
- Pool sizing must account for all service replicas.
- Graceful shutdown needs a bounded drain and recovery plan.