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 h.samplingRate #11

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

kovin
Copy link

@kovin kovin commented Nov 20, 2023

closes #10

The Avo inspector handler can't be used concurrently given that h.samplingRate allows for race conditions where different go-routines can read it and/or write to it.

It's being read here and written here.

In avoNetworkCallsHandler_test.go we're adding coverage to assert that no race condition happens when the inspector is used concurrently by different go-routines.

ioutil.ReadAll() has been deprecated since Go 1.16
By holding the tracking endpoint as part of AvoNetworkCallsHandler we
are able to change it for test purposes and thus we're able to add coverage
for callInspectorWithBatchBody()
If the Avo inspector handler is used concurrently by different go-routines
then the h.samplingRate can have race conditions where it's trying to be
read/written at the same time
The new test can be executed using:
    go test -run TestAvoNetworkCallsHandler_callInspectorWithBatchBody -race -timeout 3s
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 this pull request may close these issues.

Fix race condition in h.samplingRate
1 participant