Skip to content
Open
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
34 changes: 34 additions & 0 deletions src/ws-ckpt/src/crates/daemon/src/listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,14 @@ pub async fn run_listener(
break;
}
}

// Reap finished connections. JoinSet holds each task's handle and output
// slot until it is joined, so without this the set grows by one entry per
// CLI invocation and is only released at shutdown. try_join_next never
// awaits, so reaping cannot delay the next accept; a join_next branch in
// the select! above would instead need a second mutable borrow of
// join_set while the accept arm still spawns into it.
while join_set.try_join_next().is_some() {}
Comment thread
yummypeng marked this conversation as resolved.
}

// 7. Wait for in-flight tasks to complete (with timeout)
Expand Down Expand Up @@ -136,3 +144,29 @@ async fn handle_connection(

Ok(())
}

#[cfg(test)]
mod tests {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

删除这个测试,因为他并没有测到你修的问题,只测试了 tokio 包本身的功能。

use tokio::task::JoinSet;

/// Pins the semantics the accept loop relies on: completed tasks stay in the
/// set until reaped, and `try_join_next` drains them without awaiting. If the
/// reap call in the accept loop is dropped, the daemon leaks one entry per
/// connection, which is what caused ~8 KB of growth per CLI invocation.
#[tokio::test]
async fn try_join_next_reaps_completed_tasks() {
let mut set = JoinSet::new();
for _ in 0..16 {
set.spawn(async {});
}
while !set.is_empty() {
let before = set.len();
if set.try_join_next().is_none() {
tokio::task::yield_now().await;
continue;
}
assert_eq!(set.len(), before - 1, "reaping must release one entry");
}
assert!(set.try_join_next().is_none(), "empty set must not block");
}
}
Loading