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

fix: child sandbox process becoming orphaned on early process termination #205

Merged
merged 1 commit into from
Oct 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions workspaces/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Library for automating workflows and testing NEAR smart contracts.

[dependencies]
async-trait = "0.1"
async-process = { version = "1.3", optional = true }
async-process = "1.3"
base64 = "0.13"
borsh = "0.9"
cargo_metadata = { version = "0.14.2", optional = true }
Expand Down Expand Up @@ -54,7 +54,7 @@ tracing-subscriber = { version = "0.3.5", features = ["env-filter"] }
[features]
default = ["install"]
install = [] # Install the sandbox binary during compile time
unstable = ["cargo_metadata", "async-process"]
unstable = ["cargo_metadata"]

[package.metadata.docs.rs]
features = ["unstable"]
2 changes: 1 addition & 1 deletion workspaces/src/network/sandbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl Sandbox {

pub(crate) async fn new() -> Result<Self> {
let mut server = SandboxServer::default();
server.start()?;
server.start().await?;
let client = Client::new(&server.rpc_addr());
client.wait_for_rpc().await?;

Expand Down
15 changes: 7 additions & 8 deletions workspaces/src/network/server.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
use std::process::Child;

use crate::error::SandboxErrorCode;
use crate::network::Sandbox;
use crate::result::Result;

use async_process::Child;
use portpicker::pick_unused_port;
use tracing::info;

// TODO: swap over the async version of this in the future. Won't be a breaking API
// since we already have async marked in the functions that we are exposing.
use near_sandbox_utils::sync as sandbox;
use near_sandbox_utils as sandbox;

pub struct SandboxServer {
pub(crate) rpc_port: u16,
Expand All @@ -26,7 +23,7 @@ impl SandboxServer {
}
}

pub fn start(&mut self) -> Result<()> {
pub async fn start(&mut self) -> Result<()> {
if self.process.is_some() {
return Err(SandboxErrorCode::AlreadyStarted.into());
}
Expand All @@ -39,10 +36,12 @@ impl SandboxServer {

// Remove dir if it already exists:
let _ = std::fs::remove_dir_all(&home_dir);
sandbox::init(&home_dir)
let output = sandbox::init(&home_dir)
.map_err(|e| SandboxErrorCode::InitFailure.custom(e))?
.wait()
.output()
.await
.map_err(|e| SandboxErrorCode::InitFailure.custom(e))?;
info!(target: "workspaces", "sandbox init: {:?}", output);

let child = sandbox::run(&home_dir, self.rpc_port, self.net_port)
.map_err(|e| SandboxErrorCode::RunFailure.custom(e))?;
Expand Down