Skip to content

Data race when using concurrency > 1 #192

Description

@mYmNeo

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions