-
Notifications
You must be signed in to change notification settings - Fork 472
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Memory leak in crossbeam_utils::thread::scope()
: Unbounded memory usage with long-lived scopes
#816
Comments
Partially related: as I know this functionality is slowly moving to std. As far as I can see their implementation doesn't have such a problem. |
Indeed! The not-yet-stable |
Note that since crossbeam's |
If someone can implement an equivalent to the standard library's scoped thread API without relying on unstable features, I would like to change the crossbeam's scoped thread API in the next breaking release. In any case, once the standard library's scoped thread is stable, I plan to soft deprecate the crossbeam's scoped thread. |
Filed #844 to fix this. |
crossbeam_utils::thread::Scope
owns a vector of shared join handles:crossbeam/crossbeam-utils/src/thread.rs
Lines 193 to 203 in 450d237
Each call to
scope.spawn()
pushes a new handle to the vec:crossbeam/crossbeam-utils/src/thread.rs
Lines 458 to 459 in 450d237
The vec never shrinks until it is drained all at once at the end of
scope()
:crossbeam/crossbeam-utils/src/thread.rs
Lines 167 to 176 in 450d237
Thus, any long-lived thread scope will exhibit unbounded memory usage as it spawns more and more threads, even if those threads finish executing or are joined by the user. This is a huge problem for servers or other such long-running applications that want to spawn scoped threads.
I would understand if there are reasons that
scope()
can't be implemented in such a way where these handles are cleaned up as threads complete. But if that is the case, then I feel this needs to be a very explicitly warned about in the crate's documentation and README. Cuz this is really bad. We believe that this issue is the root cause of a recent out-of-memory crash on an enterprise customer's deployment of our software product.The text was updated successfully, but these errors were encountered: