diff --git a/Cargo.lock b/Cargo.lock index 99ac1effb..ffbd1ba8c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6640,8 +6640,7 @@ dependencies = [ [[package]] name = "sharded-slab" version = "0.1.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f40ca3c46823713e0d4209592e8d6e826aa57e928f09752619fc696c499637f6" +source = "git+https://github.com/tlsnotary/sharded-slab#5dd1d23d5b1f57e52b1858cb3c42ef4748062f3b" dependencies = [ "lazy_static", ] @@ -7665,6 +7664,7 @@ dependencies = [ "rayon", "serde", "serde_json", + "sharded-slab", "time", "tlsn", "tlsn-core", @@ -8415,9 +8415,8 @@ dependencies = [ [[package]] name = "web-spawn" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81aa4e191851788bbf25b06490e2800a3ca4f4da98d2da1b8a612af98526bbb1" +version = "0.3.0" +source = "git+https://github.com/tlsnotary/tlsn-utils?rev=f674edd#f674eddff4b0c29fed5ea16d0d25816d6124dd5d" dependencies = [ "crossbeam-channel", "futures", diff --git a/Cargo.toml b/Cargo.toml index 7681dd011..5ec649135 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -148,6 +148,7 @@ sct = { version = "0.7" } semver = { version = "1.0" } serde = { version = "1.0" } serde_json = { version = "1.0" } +sharded-slab = { version = "0.1" } sha2 = { version = "0.10" } signature = { version = "2.2" } thiserror = { version = "1.0" } @@ -162,9 +163,14 @@ tracing = { version = "0.1" } tracing-subscriber = { version = "0.3" } wasm-bindgen = { version = "0.2" } wasm-bindgen-futures = { version = "0.4" } -web-spawn = { version = "0.2" } +web-spawn = { git = "https://github.com/tlsnotary/tlsn-utils", rev = "f674edd" } web-time = { version = "0.2" } webpki-roots = { version = "1.0" } webpki-root-certs = { version = "1.0" } ws_stream_wasm = { version = "0.7.5" } zeroize = { version = "1.8" } + +[patch.crates-io] +# Replace sharded-slab with a wasm-friendly fork that provides explicit +# thread-id cleanup (wasm-bindgen does not run Rust TLS destructors). +sharded-slab = { git = "https://github.com/tlsnotary/sharded-slab" } \ No newline at end of file diff --git a/crates/harness/executor/Cargo.toml b/crates/harness/executor/Cargo.toml index 18b91a6ff..2ed06aade 100644 --- a/crates/harness/executor/Cargo.toml +++ b/crates/harness/executor/Cargo.toml @@ -5,8 +5,7 @@ edition = "2024" publish = false [features] -# Disable tracing events as a workaround for issue 959. -default = ["tracing/release_max_level_off"] +default = [] # Used to debug the executor itself. debug = [] diff --git a/crates/harness/executor/src/wasm.rs b/crates/harness/executor/src/wasm.rs index 69a7e8c57..51aadd2f3 100644 --- a/crates/harness/executor/src/wasm.rs +++ b/crates/harness/executor/src/wasm.rs @@ -12,6 +12,7 @@ use harness_core::{ use crate::Executor; +#[allow(unused_imports)] pub use tlsn_wasm::*; unsafe extern "C" { diff --git a/crates/wasm/Cargo.toml b/crates/wasm/Cargo.toml index 3393444c3..a74b5e783 100644 --- a/crates/wasm/Cargo.toml +++ b/crates/wasm/Cargo.toml @@ -38,6 +38,7 @@ pin-project-lite = { workspace = true } rayon = { workspace = true } serde = { workspace = true, features = ["derive"] } serde_json = { version = "1.0" } +sharded-slab = { workspace = true } time = { version = "=0.3.37", features = ["wasm-bindgen"] } tracing = { workspace = true } tracing-subscriber = { workspace = true, features = ["time"] } diff --git a/crates/wasm/src/log.rs b/crates/wasm/src/log.rs index f1fe7e73b..69c85789c 100644 --- a/crates/wasm/src/log.rs +++ b/crates/wasm/src/log.rs @@ -123,3 +123,16 @@ pub(crate) fn filter(config: LoggingConfig) -> impl Fn(&Metadata) -> bool { meta.level() <= level } } + +#[no_mangle] +pub(crate) extern "C" fn __worker_teardown() { + use sharded_slab::DefaultConfig; + // Manually release sharded_slab's per-thread state. + // + // On native targets this would normally be cleaned up by Rust's + // thread-local destructors when a thread exits. However, in the + // wasm32 + wasm-bindgen threading model, TLS destructors are not + // invoked when a Web Worker is terminated. As a result, we must + // perform this cleanup explicitly before the worker is destroyed. + sharded_slab::release_current_thread_id::(); +}