fix(ckpt): reap finished tasks in accept loop - #2554
Open
qiwu575757 wants to merge 1 commit into
Open
Conversation
The accept loop spawned every connection into a `JoinSet` but only reaped it at shutdown, so the set kept one entry — task handle plus output slot — for each connection that had already finished. Every ws-ckpt CLI invocation opens one socket connection, so the daemon grew monotonically for its whole lifetime and only released the memory on exit. Measured on 5.10.134-19.6.3 with ws-ckpt 0.4.2, the growth was linear in connection count and independent of both the storage backend and the kind of operation, which is what identified the connection path rather than snapshot state as the source: btrfs-base 10h soak 7.8-7.9 KB per operation btrfs-loop 10h soak 7.9-8.0 KB per operation loop, direct-io, 10h 8.0 KB per operation isolated 60s sample 8.4 KB per operation VmData tracked VmRSS almost exactly (5418 MB of 5366 MB resident), the file descriptor count stayed flat, and the snapshot pool was held constant during the soaks, so the growth was heap held by the daemon rather than page cache, descriptors, or index state. A `kill -9` returned RSS from 5.7 GB to 46 MB. Under a checkpoint-heavy agent workload this reaches roughly 370 MB/h, and about 1.7 GB/h under the functional suite, so a long-lived daemon eventually OOMs. Drain completed tasks with `try_join_next` after each select iteration. It is synchronous, so reaping cannot delay the next accept, and it avoids the second mutable borrow of `join_set` that a `join_next` branch inside the same `select!` would need while the accept arm still spawns into the set. Shutdown still drains with `join_next` under the existing timeout, so in-flight connections keep their grace period. After the change, 20000 operations grow RSS by 2.6 MB (0.13 KB per operation, down from ~8 KB), and a further 40000 operations add 2.0 MB in total with no linear trend, i.e. what remains is allocator headroom rather than accumulation. Descriptors stay at 14. Signed-off-by: Qi Wu <shijing.wq@alibaba-inc.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e4040e7e90
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
yummypeng
reviewed
Aug 17, 2026
| @@ -136,3 +144,29 @@ async fn handle_connection( | |||
|
|
|||
| Ok(()) | |||
| } | |||
|
|
|||
| #[cfg(test)] | |||
| mod tests { | |||
Collaborator
There was a problem hiding this comment.
删除这个测试,因为他并没有测到你修的问题,只测试了 tokio 包本身的功能。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The accept loop spawned every connection into a
JoinSetbut only reaped it at shutdown, so the set kept one entry — task handle plus output slot — for each connection that had already finished. Every ws-ckpt CLI invocation opens one socket connection, so the daemon grew monotonically for its whole lifetime and only released the memory on exit.Measured on 5.10.134-19.6.3 with ws-ckpt 0.4.2, the growth was linear in connection count and independent of both the storage backend and the kind of operation, which is what identified the connection path rather than snapshot state as the source:
btrfs-base 10h soak 7.8-7.9 KB per operation
btrfs-loop 10h soak 7.9-8.0 KB per operation
loop, direct-io, 10h 8.0 KB per operation
isolated 60s sample 8.4 KB per operation
VmData tracked VmRSS almost exactly (5418 MB of 5366 MB resident), the file descriptor count stayed flat, and the snapshot pool was held constant during the soaks, so the growth was heap held by the daemon rather than page cache, descriptors, or index state. A
kill -9returned RSS from 5.7 GB to 46 MB. Under a checkpoint-heavy agent workload this reaches roughly 370 MB/h, and about 1.7 GB/h under the functional suite, so a long-lived daemon eventually OOMs.Drain completed tasks with
try_join_nextafter each select iteration. It is synchronous, so reaping cannot delay the next accept, and it avoids the second mutable borrow ofjoin_setthat ajoin_nextbranch inside the sameselect!would need while the accept arm still spawns into the set. Shutdown still drains withjoin_nextunder the existing timeout, so in-flight connections keep their grace period.After the change, 20000 operations grow RSS by 2.6 MB (0.13 KB per operation, down from ~8 KB), and a further 40000 operations add 2.0 MB in total with no linear trend, i.e. what remains is allocator headroom rather than accumulation. Descriptors stay at 14.