-
Notifications
You must be signed in to change notification settings - Fork 18k
compress/gzip: memory leak using gzip.Writer #58455
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
Comments
In general, if there are constructors provided, it's expected for you to use them (unless the zero value has been explicitly documented to work). |
Given that (1) |
Timed out in state WaitingForInfo. Closing. (I am just a bot, though. Please speak up if this is a mistake or you have the requested information.) |
I can't actually share the memory leak proof. As it was work related and running pprof on the code will entail more parts of the project. One Major issue that I wanted to highlight. You can use new(gzip.Writer) instead of using the function gzip.NewWriter(). In the first case we don't provide a writer to the pkg. But it still complies. As I said I am not sure if it's a Bug or not |
@kitarp29 Thanks, but code like |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?GOHOSTOS="linux" which is on Ubuntu 20.04, also tried it on MacOS.
go env
OutputWhat did you do?
This was an issue I ran into while at work this week. We are building a service on Golang and compressing the data before I save it to the DB. We tried using compress/gzip.
Implemented the basic way to compress the data using the NewWriter Function : Here. Problem is that when we tried this solution at scale(1 million entries at a time) there was a memory leak. We did Lfush and close all the writers and buffers we used. Still, it continued, verified using pprof.
We made an in-house implementation to solve the issue. We used
new(gzip.Writer)
to create a Writer for us.Tried like the last implementation, but to our surprise, it did not compress the string at all. In fact, the compressed data was larger than the original!
There was no compilation error whatsoever. Reason it increased was as the file/data is compressed an extra footer and added is added. After going through the code of gzip: Here
I realized that when we use
gzip.NewWriter()
we are expected to pass an io.writer. This writer replaces the writer in the struct of gzip.Writer. I am assuming only then does it compresses the file.Even I am not sure if it is BUG or not. I just wanted to share this and reduce the pain for someone else using this pkg.
What did you expect to see?
The pkg to compress the data provided. But it did not.
What did you see instead?
An uncompressed, even increased data than original
The text was updated successfully, but these errors were encountered: