///
/// Increase file handle limits as much as the OS will allow us to, returning an error if we are
/// unable to either get or sufficiently raise them. Generally the returned error should be treated
/// as a warning to be rendered rather than as something fatal.
///
Increase file handle limits as much as the OS will allow us to, returning an error if we are
unable to either get or sufficiently raise them. Generally the returned error should be treated
as a warning to be rendered rather than as something fatal.
Increase file handle limits as much as the OS will allow us to returning an error if we are unable to either get or sufficiently raise them . Generally the returned error should be treated as a warning to be rendered rather than as something fatal .
pub fn increase_limits() -> Result<String, String> {
  loop {
    let (cur, max) = rlimit::Resource::NOFILE
      .get()
      .map_err(|e| format!("Could not validate file handle limits: {}", e))?;
    // If the limit is less than our target.
    if cur < TARGET_NOFILE_LIMIT {
      let err_suffix = format!(
        "To avoid 'too many open file handle' errors, we recommend a limit of at least {}: \
        please see https://www.pantsbuild.org/docs/troubleshooting#too-many-open-files-error \
        for more information.",
        TARGET_NOFILE_LIMIT
      );
      // If we might be able to increase the limit, try to.
      if cur < max {
        rlimit::Resource::NOFILE.set(max, max).map_err(|e| {
          format!(
            "Could not raise file handle limit above {}: `{}`. {}",
            cur, e, err_suffix
          )
        })?;
      } else {
        return Err(format!(
          "File handle limit is capped to: {}. {}",
          cur, err_suffix
        ));
      }
    } else {
      return Ok(format!("File handle limit is: {}", cur));
    };
  }
}
pub fn increase_limits ( ) -> Result < String , String > { loop { let ( cur , max ) = rlimit :: Resource :: NOFILE . get ( ) . map_err ( | e | format ! ( " " e ) ) ? ; // If the limit is less than our target. if cur < TARGET_NOFILE_LIMIT { let err_suffix = format ! ( " \
 \
 " TARGET_NOFILE_LIMIT ) ; // If we might be able to increase the limit, try to. if cur < max { rlimit :: Resource :: NOFILE . set ( max , max ) . map_err ( | e | { format ! ( " " cur e err_suffix ) } ) ? ; } else { return Err ( format ! ( " " cur err_suffix ) ) ; } } else { return Ok ( format ! ( " " cur ) ) ; } ; } }
Increase file handle limits as much as the OS will allow us to, returning an error if we are
unable to either get or sufficiently raise them.
Increase file handle limits as much as the OS will allow us to returning an error if we are unable to either get or sufficiently raise them .