Skip to content

Commit 0602a72

Browse files
authored
Merge pull request #2344 from rbtcollins/limits
Handle effective limits lookups failing
2 parents 53b2168 + 96f72d0 commit 0602a72

File tree

4 files changed

+33
-20
lines changed

4 files changed

+33
-20
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ chrono = "0.4"
2525
clap = "2"
2626
download = { path = "download" }
2727
error-chain = "0.12"
28-
effective-limits = "0.4"
28+
effective-limits = "0.5"
2929
flate2 = "1"
3030
git-testament = "0.1.4"
3131
home = "0.5"

src/dist/component/package.rs

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -167,13 +167,19 @@ struct MemoryBudget {
167167
impl MemoryBudget {
168168
fn new(
169169
max_file_size: usize,
170-
effective_max_ram: usize,
170+
effective_max_ram: Option<usize>,
171171
notify_handler: Option<&dyn Fn(Notification<'_>)>,
172172
) -> Self {
173173
const DEFAULT_UNPACK_RAM_MAX: usize = 500 * 1024 * 1024;
174174
const RAM_ALLOWANCE_FOR_RUSTUP_AND_BUFFERS: usize = 100 * 1024 * 1024;
175-
let ram_for_unpacking = effective_max_ram - RAM_ALLOWANCE_FOR_RUSTUP_AND_BUFFERS;
176-
let default_max_unpack_ram = std::cmp::min(DEFAULT_UNPACK_RAM_MAX, ram_for_unpacking);
175+
let default_max_unpack_ram = if let Some(effective_max_ram) = effective_max_ram {
176+
let ram_for_unpacking = effective_max_ram - RAM_ALLOWANCE_FOR_RUSTUP_AND_BUFFERS;
177+
std::cmp::min(DEFAULT_UNPACK_RAM_MAX, ram_for_unpacking)
178+
} else {
179+
// Rustup does not know how much RAM the machine has: use the
180+
// minimum known to work reliably.
181+
DEFAULT_UNPACK_RAM_MAX
182+
};
177183
let unpack_ram = match env::var("RUSTUP_UNPACK_RAM")
178184
.ok()
179185
.and_then(|budget_str| budget_str.parse::<usize>().ok())
@@ -291,12 +297,16 @@ fn unpack_without_first_dir<'a, R: Read>(
291297
.entries()
292298
.chain_err(|| ErrorKind::ExtractingPackage)?;
293299
const MAX_FILE_SIZE: u64 = 200_000_000;
294-
let effective_max_ram = effective_limits::memory_limit()?;
295-
let mut budget = MemoryBudget::new(
296-
MAX_FILE_SIZE as usize,
297-
effective_max_ram as usize,
298-
notify_handler,
299-
);
300+
let effective_max_ram = match effective_limits::memory_limit() {
301+
Ok(ram) => Some(ram as usize),
302+
Err(e) => {
303+
if let Some(h) = notify_handler {
304+
h(Notification::Error(e.to_string()))
305+
}
306+
None
307+
}
308+
};
309+
let mut budget = MemoryBudget::new(MAX_FILE_SIZE as usize, effective_max_ram, notify_handler);
300310

301311
let mut directories: HashMap<PathBuf, DirStatus> = HashMap::new();
302312
// Path is presumed to exist. Call it a precondition.

src/utils/notifications.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ pub enum Notification<'a> {
3131
/// member, but the notification callback is already narrowed to
3232
/// utils::notifications by the time tar unpacking is called.
3333
SetDefaultBufferSize(usize),
34+
Error(String),
3435
UsingCurl,
3536
UsingReqwest,
3637
/// Renaming encountered a file in use error and is retrying.
@@ -60,6 +61,7 @@ impl<'a> Notification<'a> {
6061
| UsingReqwest => NotificationLevel::Verbose,
6162
RenameInUse(_, _) | SetDefaultBufferSize(_) => NotificationLevel::Info,
6263
NoCanonicalPath(_) => NotificationLevel::Warn,
64+
Error(_) => NotificationLevel::Error,
6365
}
6466
}
6567
}
@@ -71,6 +73,7 @@ impl<'a> Display for Notification<'a> {
7173
CreatingDirectory(name, path) => {
7274
write!(f, "creating {} directory: '{}'", name, path.display())
7375
}
76+
Error(e) => write!(f, "error: '{}'", e),
7477
LinkingDirectory(_, dest) => write!(f, "linking directory from: '{}'", dest.display()),
7578
CopyingDirectory(src, _) => write!(f, "copying directory from: '{}'", src.display()),
7679
RemovingDirectory(name, path) => {

0 commit comments

Comments
 (0)