Memory leaks may occur during stream compression with Zstd.
Describe the bug We are working on an access-layer gateway service with a custom streaming protocol over TCP. We use Zstd for stream compression. However, after implementing Zstd, we observed a continuous slight increase in memory usage. Specifically, memory usage grows by about 65 MB per day.
Our application is developed in Rust, and we use the zstd-safe library. After closely examining the zstd-safe code, I found that it releases the Zstd context during the drop phase. Therefore, I suspect that there might be some memory leaks in the Zstd C++ code in certain areas.
Does anyone have good leads or ideas to analyze and troubleshoot this issue?
To Reproduce Currently, the issue can only be reproduced in our production environment, where a large number of real connections and data are involved. Therefore, we are currently unable to provide an easy reproduction path in the test environment.
Desktop (please complete the following information): PRETTY_NAME="Debian GNU/Linux 11 (bullseye)" NAME="Debian GNU/Linux" VERSION_ID="11" VERSION="11 (bullseye)" VERSION_CODENAME=bullseye ID=debian Version=1.5.6
Therefore, I suspect that there might be some memory leaks in the Zstd C++ code in certain areas.
which C++ code?
which binding are you using?
zstd c++ v1.5.6 rust https://github.com/gyscos/zstd-rs
libzstd is written in C90, not C++.
If you were using zstd with C++, your stack would include a C++ binding layer, which could introduce its own memory management challenges. However, since you’re using zstd-rs (a Rust binding layer for libzstd), there isn’t a C++ layer in this case.
Any layer in your stack, including your application, could potentially encounter memory issues. libzstd itself is widely used and thoroughly scrutinized by multiple major organizations, making an unnoticed memory leak less likely in this layer. Therefore, it is prudent to also examine the layers above it.
I apologized for not understanding your question earlier. Indeed, I am using Rust(Zstd-rs) bindings for Zstd. Theoretically, memory leaks should not occur, but in practice, we have observed such an issue in our application. Thank you very much for your response. I will first conduct a thorough review of our application code. Once again, thank you.