Skip to content
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

Data race when using concurrency > 1 #192

Open
mYmNeo opened this issue Aug 22, 2022 · 0 comments
Open

Data race when using concurrency > 1 #192

mYmNeo opened this issue Aug 22, 2022 · 0 comments

Comments

@mYmNeo
Copy link

mYmNeo commented Aug 22, 2022

In v4 branch, the lz library may cause data corrupt if you have set concurrency > 1. The race problem happens at

https://github.com/pierrec/lz4/blob/v4/writer.go#L100
https://github.com/pierrec/lz4/blob/v4/writer.go#L159

Suppose this scenario, the calling sequences are Write, Flush, Write, Flush repeatedly, this is a very common scenario in web server.
When w.data is filled with data but doesn't reach the buffer size, calling Flush will send w.data[:w.idx] to channel and reset w.idx to zero. Here comes the problem because w.data[:w.idx] is a shadow copy of slice, that means a new call of Write and compression gorouting writes and reads the same underlaying byte array with an overlap index.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant