Skip to content
Open
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
3,179 changes: 1,830 additions & 1,349 deletions Cargo.lock

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ tokio-util = { version = "0.7", default-features = false }
cfg-if = "1.0"

# wasmtime
wasmtime = { version = "36.0.6", features = ["async"] }
wasmtime-wasi = { version = "36.0.6" }
wasmtime-wasi-http = { version = "36.0.6" }
wasmtime = { version = "43.0.1", features = ["async"] }
wasmtime-wasi = { version = "43.0.1" }
wasmtime-wasi-http = { version = "43.0.1" }

[profile.release]
panic = "abort"
4 changes: 2 additions & 2 deletions crates/containerd-shim-wasmer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ containerd-shim-wasm = { workspace = true, features = ["opentelemetry"] }
log = { workspace = true }
tokio = { workspace = true }

wasmer = "6.0.1"
wasmer-wasix = "0.600.1"
wasmer = "6.1.0"
wasmer-wasix = "0.601.0"
Comment on lines +12 to +13
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wasmtime-wasi 43.0.1 requires url >= 2.5.7, and wasmer-package 0.600.1 pins url =2.5.2.
Updated them so it relax to url = ^2.5.

mio = { version = "1", features = ["net"] }

[dev-dependencies]
Expand Down
16 changes: 10 additions & 6 deletions crates/containerd-shim-wasmtime/src/http_proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ use tokio_util::sync::CancellationToken;
use tokio_util::task::TaskTracker;
use wasmtime::Store;
use wasmtime::component::ResourceTable;
use wasmtime_wasi_http::bindings::ProxyPre;
use wasmtime_wasi_http::bindings::http::types::Scheme;
use wasmtime_wasi_http::body::HyperOutgoingBody;
use wasmtime_wasi_http::WasiHttpCtx;
use wasmtime_wasi_http::io::TokioIo;
use wasmtime_wasi_http::{WasiHttpCtx, WasiHttpView};
use wasmtime_wasi_http::p2::WasiHttpView;
use wasmtime_wasi_http::p2::bindings::ProxyPre;
use wasmtime_wasi_http::p2::bindings::http::types::Scheme;
use wasmtime_wasi_http::p2::body::HyperOutgoingBody;

use crate::instance::{WasiPreview2Ctx, envs_from_ctx};

Expand Down Expand Up @@ -194,8 +195,11 @@ impl ProxyHandler {

let mut store = self.wasi_store_for_request(req_id);

let req = store.data_mut().new_incoming_request(Scheme::Http, req)?;
let out = store.data_mut().new_response_outparam(sender)?;
let req = store
.data_mut()
.http()
.new_incoming_request(Scheme::Http, req)?;
let out = store.data_mut().http().new_response_outparam(sender)?;
let proxy = self.instance_pre.instantiate_async(&mut store).await?;

let task = self.tracker.spawn(async move {
Expand Down
34 changes: 18 additions & 16 deletions crates/containerd-shim-wasmtime/src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ use tokio_util::sync::CancellationToken;
use wasmtime::component::types::ComponentItem;
use wasmtime::component::{self, Component, ResourceTable};
use wasmtime::{Config, Module, Precompiled, Store};
use wasmtime_wasi::p1::{self as wasi_p1, WasiP1Ctx};
use wasmtime_wasi::p2::bindings::Command;
use wasmtime_wasi::preview1::{self as wasi_preview1, WasiP1Ctx};
use wasmtime_wasi::{WasiCtx, WasiCtxBuilder, WasiCtxView, WasiView};
use wasmtime_wasi_http::bindings::ProxyPre;
use wasmtime_wasi_http::{WasiHttpCtx, WasiHttpView};
use wasmtime_wasi_http::WasiHttpCtx;
use wasmtime_wasi_http::p2::bindings::ProxyPre;
use wasmtime_wasi_http::p2::{WasiHttpCtxView, WasiHttpView};

use crate::http_proxy::serve_conn;

Expand Down Expand Up @@ -67,7 +68,6 @@ impl Default for WasmtimeSandbox {
// see https://github.com/containerd/runwasi/pull/405#issuecomment-1928468714 for details
config.parallel_compilation(!cfg!(test));
config.wasm_component_model(true); // enable component linking
config.async_support(true); // must be on

if use_pooling_allocator_by_default() {
let cfg = wasmtime::PoolingAllocationConfig::default();
Expand All @@ -76,6 +76,7 @@ impl Default for WasmtimeSandbox {

Self {
engine: wasmtime::Engine::new(&config)
.map_err(anyhow::Error::from)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In wasmtime 43 wasmtime::Error becomes its own type separate from anyhow::Error.
We might want to adapt to the wasmtime::Error from anyhow::Error in future.

.context("failed to create wasmtime engine")
.unwrap(),
cancel: CancellationToken::new(),
Expand Down Expand Up @@ -111,12 +112,12 @@ impl WasiView for WasiPreview2Ctx {
}

impl WasiHttpView for WasiPreview2Ctx {
fn ctx(&mut self) -> &mut wasmtime_wasi_http::WasiHttpCtx {
&mut self.wasi_http
}

fn table(&mut self) -> &mut ResourceTable {
&mut self.resource_table
fn http(&mut self) -> WasiHttpCtxView<'_> {
WasiHttpCtxView {
ctx: &mut self.wasi_http,
table: &mut self.resource_table,
hooks: Default::default(),
}
}
}

Expand All @@ -139,7 +140,6 @@ impl Shim for WasmtimeShim {
// see https://github.com/containerd/runwasi/pull/405#issuecomment-1928468714 for details
config.parallel_compilation(!cfg!(test));
config.wasm_component_model(true); // enable component linking
config.async_support(true); // must be on

let engine = wasmtime::Engine::new(&config)
.expect("failed to create wasmtime precompilation engine");
Expand Down Expand Up @@ -214,9 +214,7 @@ impl WasmtimeSandbox {
let mut module_linker = wasmtime::Linker::new(&self.engine);

log::debug!("init linker");
wasi_preview1::add_to_linker_async(&mut module_linker, |wasi_ctx: &mut WasiP1Ctx| {
wasi_ctx
})?;
wasi_p1::add_to_linker_async(&mut module_linker, |wasi_ctx: &mut WasiP1Ctx| wasi_ctx)?;

log::info!("instantiating instance");
let instance: wasmtime::Instance =
Expand All @@ -232,6 +230,7 @@ impl WasmtimeSandbox {
start_func
.call_async(&mut store, &[], &mut [])
.await
.map_err(anyhow::Error::from)
.into_error_code()
}

Expand All @@ -254,7 +253,7 @@ impl WasmtimeSandbox {
log::info!("Found HTTP proxy target");
let mut linker = component::Linker::new(&self.engine);
wasmtime_wasi::p2::add_to_linker_async(&mut linker)?;
wasmtime_wasi_http::add_only_http_to_linker_async(&mut linker)?;
wasmtime_wasi_http::p2::add_only_http_to_linker_async(&mut linker)?;

let pre = linker.instantiate_pre(&component)?;
log::info!("pre-instantiate_pre");
Expand Down Expand Up @@ -295,7 +294,10 @@ impl WasmtimeSandbox {
))?;

log::debug!("running exported function {func:?} {start_func:?}");
start_func.call_async(&mut store, &[], &mut []).await
start_func
.call_async(&mut store, &[], &mut [])
.await
.map_err(anyhow::Error::from)
}
};

Expand Down
8 changes: 4 additions & 4 deletions crates/containerd-shimkit/src/sandbox/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,10 @@ fn get_mem(pid: u32) -> (usize, usize) {
if let Some(rest) = rest.strip_suffix("kB") {
total = rest.trim().parse().unwrap_or(0);
}
} else if let Some(rest) = line.strip_prefix("VmHWM:") {
if let Some(rest) = rest.strip_suffix("kB") {
rss = rest.trim().parse().unwrap_or(0);
}
} else if let Some(rest) = line.strip_prefix("VmHWM:")
&& let Some(rest) = rest.strip_suffix("kB")
{
rss = rest.trim().parse().unwrap_or(0);
}
}
(rss, total)
Expand Down
12 changes: 6 additions & 6 deletions crates/containerd-shimkit/src/sandbox/oci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,12 @@ pub(crate) fn setup_prestart_hooks(hooks: &Option<oci_spec::runtime::Hooks>) ->
// error, in the case that the hook command is waiting for us to
// write to stdin.
let state = format!("{{ \"pid\": {} }}", std::process::id());
if let Err(e) = stdin.write_all(state.as_bytes()) {
if e.kind() != ErrorKind::BrokenPipe {
// Not a broken pipe. The hook command may be waiting
// for us.
let _ = hook_process.kill();
}
if let Err(e) = stdin.write_all(state.as_bytes())
&& e.kind() != ErrorKind::BrokenPipe
{
// Not a broken pipe. The hook command may be waiting
// for us.
let _ = hook_process.kill();
}
}
hook_process.wait()?;
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[toolchain]
channel="1.86.0"
channel="1.91.0"
profile="default"
targets = ["wasm32-wasip1"]
Loading