Skip to content

fix(startup): auto-raise file descriptor soft limit to prevent "Too many open files"#25251

Open
vparfonov wants to merge 1 commit intovectordotdev:masterfrom
vparfonov:raise-fd-limit
Open

fix(startup): auto-raise file descriptor soft limit to prevent "Too many open files"#25251
vparfonov wants to merge 1 commit intovectordotdev:masterfrom
vparfonov:raise-fd-limit

Conversation

@vparfonov
Copy link
Copy Markdown
Contributor

Summary

Many systems default the RLIMIT_NOFILE soft limit to 1024 (Linux) or 256 (macOS), which is too low for Vector when it monitors large numbers of log files - common in Kubernetes environments. This causes "Too many open files (os error 24)" crashes.

This PR raises the soft file descriptor limit to the hard limit at Vector startup, before any sources open files. On macOS, where the hard limit can be RLIM_INFINITY (which setrlimit rejects), Vector falls back to the kernel-enforced kern.maxfilesperproc (typically 10240).

Changes:

  • Cargo.toml: add libc dep and "resource" feature to nix for rlimit access
  • src/cli.rs: call raise_file_descriptor_limit() in init_global() before metrics init,with macOS kern.maxfilesperproc fallback

Vector configuration

No configuration changes — this runs unconditionally at startup

How did you test this PR?

Unit tests: 3 tests in cli::tests (raise limit, already-at-max, macOS sysctl)

Change Type

  • Bug fix
  • New feature
  • Dependencies
  • Non-functional (chore, refactoring, docs)
  • Performance

Is this a breaking change?

  • Yes
  • No

Does this PR include user facing changes?

  • Yes. Please add a changelog fragment based on our guidelines.
  • No. A maintainer will apply the no-changelog label to this PR.

References

Notes

  • Please read our Vector contributor resources.
  • Do not hesitate to use @vectordotdev/vector to reach out to us regarding this PR.
  • Some CI checks run only after we manually approve them.
    • We recommend adding a pre-push hook, please see this template.
    • Alternatively, we recommend running the following locally before pushing to the remote branch:
      • make fmt
      • make check-clippy (if there are failures it's possible some of them can be fixed with make clippy-fix)
      • make test
  • After a review is requested, please avoid force pushes to help us review incrementally.
    • Feel free to push as many commits as you want. They will be squashed into one before merging.
    • For example, you can run git merge origin master and git push.
  • If this PR introduces changes Vector dependencies (modifies Cargo.lock), please
    run make build-licenses to regenerate the license inventory and commit the changes (if any). More details on the dd-rust-license-tool.

…any open files"

Many systems default RLIMIT_NOFILE soft limit to 1024 (Linux) or 256 (macOS),
which is too low when Vector monitors large numbers of log files. This raises
the soft limit to the hard limit at startup, with a macOS fallback to
kern.maxfilesperproc.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@vparfonov vparfonov requested a review from a team as a code owner April 23, 2026 05:46
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e90c94531d

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/cli.rs
Comment thread src/cli.rs
}
}

/// Raise the soft file descriptor limit (RLIMIT_NOFILE) as high as the OS allows.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we expose this option as a CLI argument instead? We can consider changing the default behavior later, it needs some more consideration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Limit number of open files at the same time

2 participants