Join our Newsletter — 33% off our NHI Course

File Descriptor Leak

File Descriptor Leak is a specific resource leak where a program keeps file descriptors open after they should be closed. An attacker can exploit repeated operations to exhaust available descriptors and disrupt service. Defenders should review close handling, process limits, and recovery paths under failure and load.

What a file descriptor leak means

A file descriptor leak happens when a program opens files, sockets, pipes, or other OS resources and fails to close them after use. The problem is not the open operation itself, but the cumulative effect of letting descriptors remain allocated across repeated requests, retries, or long-running workflows.

This matters because file descriptors are a finite per-process and sometimes per-system resource. When a service keeps consuming them, it can stop opening new files, accepting connections, or creating child processes, even if CPU and memory still look healthy.

Leak bugs often hide in success-path assumptions and especially in error handling, where one branch closes a descriptor and another branch returns early. That is why careful cleanup logic and failure-path testing are part of the definition, not an optional hardening step.

How descriptor leaks degrade service behaviour

The most common effect is gradual exhaustion: the application works at first, then becomes unstable under load, and eventually fails in ways that look unrelated to the original bug. A web server may stop accepting connections, a worker may fail to read configuration, or a job runner may fail to spawn new tasks.

Because the leak accumulates over time, it is often triggered by traffic patterns rather than a single malformed input. Repeated operations, partial failures, timeouts, and reconnect loops can all amplify the leak until the process hits its descriptor limit.

Operationally, this is why descriptor leaks are often grouped with resource-exhaustion weaknesses in secure coding guidance. The root issue is not malicious content in the file itself, but unchecked lifecycle handling of a scarce operating-system resource.

How teams identify exposure and confirm the root cause

Exposure review starts with process inventory and runtime observation: which services open many files or sockets, which ones are long-lived, and which workloads show steadily rising descriptor counts. The key question is whether descriptor use returns to baseline after the workload finishes.

Engineers typically confirm the issue by correlating failures with open-descriptor growth, then tracing the code paths that open resources without matching close calls. Vendor and platform diagnostics can help, but the strongest evidence usually comes from reproducing the load pattern and watching descriptor counts climb.

Post-patch review should also look for partial-compromise conditions. If a leak was used to force repeated restarts, error storms, or degraded availability, the team should confirm whether logs, queues, or dependent services were affected during the outage window.

Remediation and defensive programming patterns

Fixes usually focus on making release unconditional: close descriptors in every exit path, handle exceptions and timeouts safely, and use language constructs that guarantee cleanup even when an operation fails. The safest pattern is to treat opening a descriptor as a paired action that must be balanced immediately or by a trusted cleanup wrapper.

Defensive limits also matter. Process-level descriptor caps, restart supervision, back-pressure, and graceful degradation can reduce blast radius while the underlying code is repaired. If a service cannot be patched immediately, those controls buy time by preventing one leaking component from taking down the whole host.

For this topic, it is also useful to map the bug to broader resource-management weakness classes, because descriptor leaks are often one instance of a wider cleanup failure pattern. When repeated failures are part of the operating model, the breach patterns in real-world compromise reporting help show how exhaustion and reliability failures can become security-relevant.

Risk and Threat Considerations

A descriptor leak becomes security-relevant when an attacker can repeatedly trigger the affected code path and drive the service into exhaustion. The result is usually denial of service, but the operational impact can extend to failed authentication, stalled event processing, interrupted monitoring, or loss of availability in a shared service.

Failure mechanism: Repeated operations or error handling paths keep allocating descriptors faster than the process closes them, until the service reaches its open-file limit and can no longer function normally.

Impact: The application may stop accepting traffic, fail to create new connections, or enter recovery loops, creating an availability problem that can spread to dependent systems.

Standards & Framework Alignment

This section maps relevant standards and security frameworks to the operational risks and controls described in this guidance.

CIS Controls v8, NIST SP 800-53 Rev 5 and OWASP ASVS set the governance and control requirements practitioners need to meet.

Framework Control / Reference Relevance
CIS Controls v8 CIS-4 — Secure Configuration of Enterprise Assets and Software Descriptor leaks are prevented and contained through secure runtime and service configuration.
Recommendation — Set and monitor process resource limits to contain descriptor exhaustion.
NIST SP 800-53 Rev 5 SI-2 — Flaw Remediation Leak fixes require correcting the software defect that leaves descriptors open.
SI-10 — Information Input Validation Unchecked inputs and error paths can trigger the repeated operations that expose descriptor leaks.
Recommendation — Patch the resource-cleanup flaw and verify the fix under load. Validate failure-triggering inputs so repeated resource allocation paths do not become exhaustible.
OWASP ASVS V15 — Secure Coding and Architecture Resource lifecycle management and cleanup belong to secure code design and review.
V16 — Security Logging and Error Handling Error and exception handling are common places where leaked descriptors are introduced.
Recommendation — Enforce paired open-close handling in code review and design verification. Test error-handling paths to ensure cleanup still occurs after exceptions and timeouts.

Practitioner Guidance

What to watch for: Treat steadily increasing open-descriptor counts as a reliability signal worth investigating, especially in services that handle high request volume or external connections. The most useful checks are the ones that compare steady-state behaviour against burst, retry, and failure conditions.

Governance implication: Ownership should sit with the service team that controls the code path, because descriptor leaks are usually fixed in implementation details rather than in infrastructure alone. Operational limits can contain the symptom, but durable correction comes from code review, failure-path testing, and release discipline.

Practitioner takeaway: If a service opens resources, it must prove it closes them under success, failure, timeout, and cancellation conditions, not just in the happy path.