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

fix: data race in remove accents #80

Merged
merged 2 commits into from
Feb 16, 2024
Merged

fix: data race in remove accents #80

merged 2 commits into from
Feb 16, 2024

Conversation

rafax
Copy link
Contributor

@rafax rafax commented Feb 15, 2024

This PR fixes a data race associated with reuse of removeAccentsTransformer - when IsProfane() or other methods are called from multiple goroutines (ex. in a HTTP Server handler), sanitization fails with slice bounds out of range errors.

The issue is fixed by using a new instance of removeAccentsTransformer for every call to removeAccents.

To reproduce, run the newly added BenchmarkIsProfaneConcurrently_WithAccents with

go test -race -benchmem -bench ^BenchmarkIsProfaneConcurrently_WithAccents$

(note - it will pass on the last commit of this branch that contains a fix).

Summary

Fix a data race in removeAccents, making ProfanityDetector safe for use from multiple goroutines.

Checklist

  • Tested and/or added tests to validate that the changes work as intended, if applicable.
  • Updated documentation in README.md, if applicable.

@rafax rafax changed the title Fix data race Fix data race in remove accents Feb 15, 2024
@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (f5715a1) 100.00% compared to head (b22822e) 100.00%.
Report is 2 commits behind head on master.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff            @@
##            master       #80   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            1         1           
  Lines          191       167   -24     
=========================================
- Hits           191       167   -24     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@TwiN TwiN changed the title Fix data race in remove accents fix: data race in remove accents Feb 16, 2024
@TwiN TwiN added the bug Something isn't working label Feb 16, 2024
@TwiN TwiN merged commit 8bf3f0f into TwiN:master Feb 16, 2024
2 checks passed
@TwiN
Copy link
Owner

TwiN commented Feb 16, 2024

@rafax Thank you for the contribution!

rafax added a commit to sourcegraph/sourcegraph-public-snapshot that referenced this pull request Feb 16, 2024
rafax added a commit to sourcegraph/sourcegraph-public-snapshot that referenced this pull request Feb 16, 2024
* rg/preconfigure_detecotr

* Chat only

* Comment

* Add TwiN/go-away#80

* Bazel
rafax added a commit to sourcegraph/sourcegraph-public-snapshot that referenced this pull request Feb 20, 2024
* rg/preconfigure_detecotr

* Chat only

* Comment

* Add TwiN/go-away#80

* Bazel

* Update go.sum

* Remove

* Use a set

* remove testing overrides

* Log pattern

* bazel

* Latency + comments

* Comment

* Reorder seen

* Comment

* Switch set implementation

* Bazel
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants