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

flac.Parse funcs are prone to data races #56

Closed
zachorosz opened this issue Apr 5, 2023 · 3 comments · Fixed by #57
Closed

flac.Parse funcs are prone to data races #56

zachorosz opened this issue Apr 5, 2023 · 3 comments · Fixed by #57

Comments

@zachorosz
Copy link

zachorosz commented Apr 5, 2023

Hello! Thanks for the wonderful library!

I'm trying to Parse multiple .flac files concurrently where each file is being parsed by its own goroutine (not multiple goroutines parsing 1 file). Getting some flakey results because readBytes func uses a global buffer and is prone to data races.

Is there any harm not using this global buffer? Could make a slice of size n in the func itself - would allocate it on the stack up until a certain size I think.

This is the commit that introduced this: e03baec (I know it's pretty old :/ )

mewmew added a commit that referenced this issue Apr 8, 2023
Use function local backing array instead. As the size of
the function local backing array is known at compile time,
hopefully it can be allocated on the stack, to avoid heap
allocations.

This issue was identified by @zachorosz.

Fixes #56.
@mewmew
Copy link
Member

mewmew commented Apr 8, 2023

Hello! Thanks for the wonderful library!

Hej Zach! Happy to hear you like the library : )

I'm trying to Parse multiple .flac files concurrently where each file is being parsed by its own goroutine (not multiple goroutines parsing 1 file). Getting some flakey results because readBytes func uses a global buffer and is prone to data races.

Is there any harm not using this global buffer? Could make a slice of size n in the func itself - would allocate it on the stack up until a certain size I think.

This is the commit that introduced this: e03baec (I know it's pretty old :/ )

Definitely helpful that you dug up the commit which introduced the race condition. Thanks!

PR #57 should resolve this.

Could you check if #57 is enough to resolve your race conditions?

Cheers,
Robin

@zachorosz
Copy link
Author

Thank you @mewmew! Pulled the branch and can confirm it works as expected!

@mewmew
Copy link
Member

mewmew commented Apr 9, 2023

Thank you @mewmew! Pulled the branch and can confirm it works as expected!

Wonderful. I'll merge PR #57 and tag the v1.0.8 release of the flac library : )

@mewmew mewmew closed this as completed in #57 Apr 9, 2023
mewmew added a commit that referenced this issue Apr 9, 2023
* meta: fix data race caused by global buffer

Use function local backing array instead. As the size of
the function local backing array is known at compile time,
hopefully it can be allocated on the stack, to avoid heap
allocations.

This issue was identified by @zachorosz.

Fixes #56.

* flac: update dependencies, run `go get -u ./...`

* readme: add release notes for v1.0.8

Issues identified:
- @ktmf01 (issue encoding 8-bps WAV audio samples)
- @zachorosz (race condition when reading meta data)
- @karlek (incorrect variable used for metadata block type in error string)
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

Successfully merging a pull request may close this issue.

2 participants