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 races in the connection state changes tests #7871

Merged
merged 1 commit into from
Jul 11, 2024
Merged

Conversation

tgoyne
Copy link
Member

@tgoyne tgoyne commented Jul 9, 2024

This produced a tsan error for me when running locally. The assignment to token1 on the main thread and the read of it on the sync worker thread didn't have any intervening synchronization and in theory the callback could read it before it's actually written. Fixing this requires adding some locking.

Conversely, listener2 doesn't actually need to be atomic since the second callback should only ever be invokved synchronously inside log_out(), and if it's called on some other thread that's a bug.

It doesn't matter here, but listener1_call_cnt = listener1_call_cnt + 1 is a nonatomic increment that will drop updates if it happens on multiple threads at once, while ++ will not.

@tgoyne tgoyne requested a review from michael-wb July 9, 2024 04:26
@tgoyne tgoyne self-assigned this Jul 9, 2024
@cla-bot cla-bot bot added the cla: yes label Jul 9, 2024
@tgoyne tgoyne added no-jira-ticket Skip checking the PR title for Jira reference and removed cla: yes labels Jul 9, 2024
Copy link
Contributor

@michael-wb michael-wb left a comment

Choose a reason for hiding this comment

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

LGTM

@cla-bot cla-bot bot added the cla: yes label Jul 10, 2024
Copy link

coveralls-official bot commented Jul 10, 2024

Pull Request Test Coverage Report for Build thomas.goyne_454

Details

  • 8 of 9 (88.89%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall first build on tg/tsan-failure at 90.983%

Changes Missing Coverage Covered Lines Changed/Added Lines %
test/object-store/sync/session/connection_change_notifications.cpp 8 9 88.89%
Totals Coverage Status
Change from base Build 2480: 91.0%
Covered Lines: 215204
Relevant Lines: 236532

💛 - Coveralls

The assignment to token1 on the main thread and the read of it on the sync
worker thread didn't have any intervening synchronization and in theory the
callback could read it before it's actually written. Fixing this requires
adding some locking.

Conversely, listener2 doesn't actually need to be atomic since the second
callback should only ever be invokved synchronously inside log_out(), and if
it's called at some other time that's a bug.

It doesn't matter here, but `listener1_call_cnt = listener1_call_cnt + 1` is a
nonatomic increment that will drop updates if it happens on multiple threads at
once, while `++` will not.
@tgoyne tgoyne force-pushed the tg/tsan-failure branch from d25f0a9 to 9bfe056 Compare July 10, 2024 16:15
@tgoyne tgoyne merged commit 5dc121b into master Jul 11, 2024
40 checks passed
@tgoyne tgoyne deleted the tg/tsan-failure branch July 11, 2024 01:03
@github-actions github-actions bot mentioned this pull request Jul 12, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 10, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cla: yes no-jira-ticket Skip checking the PR title for Jira reference
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants