fix(threadstats): ensure MetricsAggregator is threadsafe#370
Merged
zippolyte merged 1 commit intoDataDog:masterfrom Jun 4, 2019
TheKevJames:threadsafe-metrics-aggregator
Merged
fix(threadstats): ensure MetricsAggregator is threadsafe#370zippolyte merged 1 commit intoDataDog:masterfrom TheKevJames:threadsafe-metrics-aggregator
zippolyte merged 1 commit intoDataDog:masterfrom
TheKevJames:threadsafe-metrics-aggregator
Conversation
zippolyte
approved these changes
Jun 4, 2019
Contributor
zippolyte
left a comment
There was a problem hiding this comment.
This LGTM, thanks a lot for this @TheKevJames
It should fix #365
|
Thanks for the fix. But to clear -- this wasn't just unsafe in python3; in python2 it was also unsafe (but less likely to trigger); I provided a script which allows reproduction in python2.7. |
dabcoder
pushed a commit
to dabcoder/datadogpy
that referenced
this pull request
Oct 25, 2019
dabcoder
pushed a commit
to dabcoder/datadogpy
that referenced
this pull request
Nov 28, 2019
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
As described in #142, the MetricsAggregator is not threadsafe under Python 3. This is a regression caused by a change in how the
.keys()method works under Python 2 vs Python 3: in Python 3, calling.keys()returns a view rather than a copy of a list.The solution here is to use a reentry lock around the modifiers and accesses to
self._metrics, in order to ensure that any concurrent calls toMetricsAggregator.flush()andMetricsAggregator.add_point()have no race conditions.Note that the stack trace which this changeset fixes is: