Skip to content

Commit

Permalink
Fix context leak.
Browse files Browse the repository at this point in the history
  • Loading branch information
cryscan committed Mar 20, 2024
1 parent 235bbaa commit d5c64a1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ keywords = ["deep-learning", "language", "model", "rwkv"]
license = "MIT OR Apache-2.0"
name = "web-rwkv"
repository = "https://github.com/cryscan/web-rwkv"
version = "0.6.30"
version = "0.6.31"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand Down
12 changes: 8 additions & 4 deletions src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,15 @@ impl<'a> ContextBuilder {
// start a thread for reading back buffers
#[cfg(not(target_arch = "wasm32"))]
{
let context = context.clone();
let context = Arc::downgrade(&context);
std::thread::spawn(move || {
while let Ok((buffer, sender)) = receiver.recv() {
let data = context.read_back_buffer(buffer);
let _ = sender.send(data);
if let Some(context) = context.upgrade() {
let data = context.read_back_buffer(buffer);
let _ = sender.send(data);
} else {
break;
}
}
});
}
Expand Down Expand Up @@ -235,7 +239,7 @@ impl PartialEq for Context {

impl Eq for Context {}

impl Context {
impl ContextInternal {
pub fn checkout_pipeline(
&self,
name: impl AsRef<str>,
Expand Down

0 comments on commit d5c64a1

Please sign in to comment.