Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set a reasonable max count on open files and don't panic if set fails #7992

Merged
merged 1 commit into from Oct 13, 2015
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Set a reasonable max count on open files and don't panic if set fails

  • Loading branch information
connorimes committed Oct 13, 2015
commit fd710eebc1037ff6e5953168f19c8c8e647cc6b7
@@ -102,15 +102,37 @@ use dom::bindings::codegen::RegisterBindings;
#[allow(unsafe_code)]
fn perform_platform_specific_initialization() {
use std::mem;
const RLIMIT_NOFILE: libc::c_int = 7;
// 4096 is default max on many linux systems
const MAX_FILE_LIMIT: libc::rlim_t = 4096;

// Bump up our number of file descriptors to save us from impending doom caused by an onslaught
// of iframes.
unsafe {
let mut rlim = mem::uninitialized();
assert!(libc::getrlimit(RLIMIT_NOFILE, &mut rlim) == 0);
rlim.rlim_cur = rlim.rlim_max;
assert!(libc::setrlimit(RLIMIT_NOFILE, &mut rlim) == 0);
let mut rlim: libc::rlimit = mem::uninitialized();
match libc::getrlimit(libc::RLIMIT_NOFILE, &mut rlim) {
0 => {
if rlim.rlim_cur >= MAX_FILE_LIMIT {
// we have more than enough
return;
}

rlim.rlim_cur = match rlim.rlim_max {
libc::RLIM_INFINITY => MAX_FILE_LIMIT,
_ => {
if rlim.rlim_max < MAX_FILE_LIMIT {
rlim.rlim_max
} else {
MAX_FILE_LIMIT
}
}
};
match libc::setrlimit(libc::RLIMIT_NOFILE, &mut rlim) {
0 => (),
_ => warn!("Failed to set file count limit"),
};
},
_ => warn!("Failed to get file count limit"),
};
}
}

ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.