Skip to content

Conversation

Sam-Amin
Copy link
Contributor

Issue:
In Histogram, some values were being dropped when the histogram is accessed concurrently by multiple threads.

Fix:
In getOrCreateHistogram, the code was copying the dictionary into a local variable, and checking it for the label without a lock. If not there, it would take the lock again to add it. But in line 224, after taking the lock again, it was rechecking the local variable, which of course would not have changed in the meantime. But the original dictionary could have changed, and that's the one we should check the second time.

Improved the concurrency test, as it was missing the bug by only checking the total count and sum without labels.

Issue:
In Histogram, some values were being dropped when the histogram is accessed concurrently by multiple threads.

Fix:
In getOrCreateHistogram, the code was copying the dictionary into a local variable, and checking it for the label without a lock. If not there, it would take the lock again to add it. But in line 224, after taking the lock again, it was rechecking the local variable, which of course would not have changed in the meantime. But the original dictionary could have changed, and that's the one we should check the second time.

Improved the concurrency test, as it was missing the bug by only checking the total count and sum without labels.
@ktoso ktoso added this to the 1.0.1 milestone Oct 18, 2022
@ktoso
Copy link
Collaborator

ktoso commented Oct 18, 2022

Nice catch, thank you @Sam-Amin !

Sorry you've hit this but very thankful for the PR :)

@ktoso ktoso merged commit 2095e26 into swift-server:master Oct 18, 2022
@ktoso
Copy link
Collaborator

ktoso commented Oct 18, 2022

I'll cut a 1.0.1 with this

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.

2 participants