Thanks to visit codestin.com
Credit goes to github.com

Skip to content

addressing concurrency issue in Span API #1259

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

Merged

Conversation

codeboten
Copy link
Contributor

Description

Before this change, the following would cause unintended behaviour in the Span API's add_event, update_name and set_status methods:

  • thread A calls set_status, locks to check if a span has ended, and releases the lock
  • thread B obtains the lock and ends a span
  • thread A continues its call of set_status

This change ensures that the update operations are done with the lock being held. It's done in a decorator, but that is completely optional.

Fixes #1157

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

I updated the code in set_status to raise an exception when the status was updated on an already ended span and was able to reproduce the issue, it was too unreliable to write a unit test for it. The only way I managed to reproduce with about 1% of the time was to introduce a delay in set_status

Checklist:

  • Followed the style guidelines of this project
  • Changelogs have been updated
  • Unit tests have been added
  • Documentation has been updated

Before this change, the following would cause unintended behaviour in the Span API's add_event, update_name and set_status methods:

- thread A calls set_status, locks to check if a span has ended, and releases the lock
- thread B obtains the lock and ends a span
- thread A continues its call of set_status

This change ensures that the update operations are done with the lock being held. It's done in a decorator, but that is completely optional.
@codeboten codeboten requested review from a team, owais and lzchen and removed request for a team October 19, 2020 23:20
@codeboten codeboten added the release:required-for-ga To be resolved before GA release label Oct 20, 2020
@@ -575,15 +586,8 @@ def set_attribute(self, key: str, value: types.AttributeValue) -> None:
with self._lock:
self.attributes[key] = value
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about set_attribute?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yeah good point, I saw the lock here and thought it was safe from this condition, but it is not. will fix

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

@codeboten codeboten requested a review from lzchen October 23, 2020 04:42
@codeboten codeboten merged commit 27dc691 into open-telemetry:master Oct 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release:required-for-ga To be resolved before GA release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Validate Span API is safe for concurrent calls
3 participants