Documentation
¶
Overview ¶
Package fdleak provides file descriptor leak detection.
It uses /proc/self/fd snapshots on Linux to take a snapshot of open file descriptors before and after running the tested function. Any file descriptors present in the "after" snapshot but not in the "before" snapshot are considered leaks.
By default, sockets, pipes, and anonymous inodes are filtered out, as these are typically managed by the Go runtime or OS internals.
This approach is inherently process-wide: /proc/self/fd lists all file descriptors for the process. Any concurrent I/O from other goroutines may cause false positives. A mutex serializes Leaked calls to prevent multiple leak checks from interfering with each other, but cannot protect against external concurrent file operations.
This package only works on Linux. On other platforms, Snapshot returns an error.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FormatLeaked ¶
FormatLeaked formats leaked file descriptors into a human-readable message. Returns the empty string if the slice is empty.
func Leaked ¶
Leaked takes a before/after snapshot around the tested function and returns a formatted description of leaked file descriptors.
Returns the empty string if no leaks are found. The caller is responsible for checking runtime.GOOS before calling.