From 9f8c59e6a90c69ac4191b546a50aeaa486c751f5 Mon Sep 17 00:00:00 2001 From: Phuong Nguyen Date: Thu, 8 Dec 2022 14:58:35 -0800 Subject: [PATCH] rebase with conf sandbox PR --- workspaces/src/network/config.rs | 17 +++++++++++++++++ workspaces/src/network/server.rs | 8 +------- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/workspaces/src/network/config.rs b/workspaces/src/network/config.rs index 86d5e72e..a41b31d2 100644 --- a/workspaces/src/network/config.rs +++ b/workspaces/src/network/config.rs @@ -53,6 +53,20 @@ fn max_sandbox_json_payload_size() -> Result { Ok(max_files) } +/// Get the max files for workspaces. `NEAR_SANDBOX_MAX_FILES` env var will be used and if not +/// specified, will default to a max of 5000 handles by default as to not ulimit errors on certain +/// platforms like Windows WSL2. +fn max_files() -> Result { + let max_files = match std::env::var("NEAR_SANDBOX_MAX_FILES") { + Ok(val) => (&val) + .parse::() + .map_err(|err| ErrorKind::DataConversion.custom(err))?, + Err(_err) => 4096, + }; + + Ok(max_files) +} + /// Set extra configs for the sandbox defined by workspaces. pub(crate) fn set_sandbox_configs(home_dir: &Path) -> Result<()> { overwrite( @@ -63,6 +77,9 @@ pub(crate) fn set_sandbox_configs(home_dir: &Path) -> Result<()> { "json_payload_max_size": max_sandbox_json_payload_size()?, }, }, + "store": { + "max_open_files": max_files()?, + } }), ) } diff --git a/workspaces/src/network/server.rs b/workspaces/src/network/server.rs index 4654f08f..68813727 100644 --- a/workspaces/src/network/server.rs +++ b/workspaces/src/network/server.rs @@ -1,10 +1,4 @@ -use std::collections::hash_map::Entry; -use std::collections::HashMap; -use std::fs::File; -use std::io::BufReader; -use std::path::PathBuf; - -use crate::error::{ErrorKind, SandboxErrorCode}; +use crate::error::SandboxErrorCode; use crate::network::Sandbox; use crate::result::Result;