Skip to content

Commit 36de5a6

Browse files
committed
fix(cli): bump open files limit on macOS and Linux
This automatically bumps the maximum number of open files (NOFILE) to the hard limit. It prevents 'Too many open files (os error 24)' which happens easily on macOS due to its low default soft limit (256). Fixes #1248
1 parent caa7d5c commit 36de5a6

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

Cargo.lock

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lychee-bin/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ tokio-stream = "0.1.18"
5656
toml = "1.0.6"
5757
url = "2.5.8"
5858
quick-junit = "0.5.2"
59+
rlimit = "0.11.0"
5960

6061

6162
[dev-dependencies]

lychee-bin/src/main.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,13 @@ enum ExitCode {
115115
const LYCHEEIGNORE_COMMENT_MARKER: &str = "#";
116116

117117
fn main() -> Result<()> {
118+
// Increase the maximum number of open files on macOS and Linux.
119+
// This is helpful because lychee opens many files concurrently during
120+
// link extraction and checking, which can exceed the default limit
121+
// of 256 open files on macOS. See https://github.com/lycheeverse/lychee/issues/1248
122+
#[cfg(any(target_os = "macos", target_os = "linux"))]
123+
let _ = rlimit::increase_nofile_limit(u64::MAX);
124+
118125
// std::process::exit doesn't guarantee that all destructors will be run,
119126
// therefore we wrap the main code in another function to ensure that.
120127
// See: https://doc.rust-lang.org/stable/std/process/fn.exit.html

0 commit comments

Comments
 (0)