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.
What does this PR do?
The
testTracingConcurrently
would regularly fail on the CI, so I took a look at it. I set the number of iterations to 3000 and it was failing ~50% of the times.There were 2 main reasons for the failures.
First, a
finishSpan
on a different thread would be called before we got the value oflastResolvedValue
in the test. It is a totally fine use case, but it would set thelastResolvedValue
tonil
and it would fail to unwrap the value later in the testThen, the call to
span.finish
was not thread-safe and so there were cases where thespan.finish
would somehow fail and we finished the tests with 1 or 2 remaining spans in thespanDictionary
.I ran the test with 3000 iterations about 40 times with the proposed changes and it did not fail once.
Why we had this feature
Digging into the history and why we're using
objc_sync_enter
, I could trace it down to this commit (and this comment more specifically).We were trying to make sure the Tracer wasn't accessed by 2 different thread, so indeed I think we should also wrap
span.finish
in the mutex.In any case this was a valid concern for the bridge package, but I'm not so sure it's needed anymore since all calls to the RN
DDTrace
module now run on the same thread anyway.Review checklist (to be filled by reviewers)