trufflehog: too many open files during filesystem scan
Fixes trufflehog 'too many open files' failures by raising the file-descriptor limit and narrowing the scan. It distinguishes fd exhaustion from memory issues and gives systemd, Docker, and CI variants. Not for OOM kills or scan-result tuning.
TL;DR
trufflehog opens many files in parallel, and the default file-descriptor limit (often 1024) runs out on big trees. Raise the limit with ulimit -n (or LimitNOFILE under systemd) and narrow the scan with path filters. The scan then completes instead of dying on EMFILE.
Error
trufflehog: too many open files during filesystem scanSteps
- Check the current limit: run
ulimit -nas the same user that runs the scan. Expected: you see a small number like 1024, which explains the failure on large trees. - Raise it for the shell session: run
ulimit -n 65535and rerun the scan in the same shell. Expected: the scan gets past the point where it previously died. - Make it durable under systemd: add
LimitNOFILE=65535to the service unit, runsystemctl daemon-reload, and restart the scan service. Expected: the new limit persists across restarts. - In Docker, start the container with
--ulimit nofile=65535:65535. Expected: the in-container scan inherits the higher limit. - Narrow the work: add
--exclude-pathsfor dependency and build directories so fewer files are opened at once. Expected: lower peak fd usage even at modest limits.
When to use
- trufflehog fails with "too many open files" or EMFILE during filesystem scans
- The same scan works on small repos but dies on large ones
- Running under Docker, systemd, or a CI runner with default ulimits
When not to use
- Exit 137 / "Killed" (that is OOM, raise memory instead)
- Scan completes but misses secrets (tuning issue)
Tool compatibility
- trufflehog v3.x; Linux
ulimit, systemdLimitNOFILE, Docker--ulimit
Variant phrasings
trufflehog EMFILE in CI
CI runners often inherit a 1024 fd limit. Raise it in the job setup step before invoking trufflehog, or shard the scan across jobs.
too many open files scanning node_modules
Exclude dependency directories with --exclude-paths; they rarely contain your secrets and dominate fd usage.
Why it happens
trufflehog walks the filesystem with concurrent workers, each holding open file descriptors for files being scanned plus detector state. On trees with hundreds of thousands of files, the default soft limit of 1024 descriptors exhausts quickly and the Go runtime surfaces EMFILE as a fatal scan error.
Provenance
Resolved from the public thread: https://vectle.com/posts/pst_DGDiy52ChyUEjUDyE-83HA