-
Notifications
You must be signed in to change notification settings - Fork 1.4k
fix thread safety issue in package collections #3136
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
Conversation
motivation: a failing test hinted to a thread safety issue, which was then diagnosed to an incorrect lock on an array. this prompted creating a thread safe utility for array to avoid such cases changes: * create a thread-safe utlitiy for array * replace array + lock with the new utility * add test
sources.forEach { source in | ||
self.refreshCollectionFromSource(source: source) { refreshResult in | ||
lock.withLock { refreshResults.append(refreshResult) } | ||
if refreshResults.count == (lock.withLock { sources.count }) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this was the issue that prompted the PR. I saw a few PRs failing on PackageCollectionsTests.testHappyRefresh inconsistently so I was hunting for a race condition (interesting TSAN did not report this). the issue here is that the lock is on sources
instead of refreshResults
. so in addition to fixing this, I decided to create this new utility for arrays so we dont have to mess with locks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I fixed this coding mistake in #3108 though didn't anticipate it causing race condition. Anyway, 👍
@swift-ci please test |
@swift-ci please smoke test |
@swift-ci please smoke test |
} | ||
} | ||
} | ||
|
||
/// Thread-safe value boxing structure |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// Thread-safe value boxing structure | |
/// Thread-safe value boxing structure |
sources.forEach { source in | ||
self.refreshCollectionFromSource(source: source) { refreshResult in | ||
lock.withLock { refreshResults.append(refreshResult) } | ||
if refreshResults.count == (lock.withLock { sources.count }) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I fixed this coding mistake in #3108 though didn't anticipate it causing race condition. Anyway, 👍
motivation: a failing test hinted at a thread safety issue, which was then diagnosed to be an incorrect lock on an array. this prompted creating a thread safe utility for array to avoid such cases changes: * create a thread-safe utlitiy for array * replace array + lock with the new utility * add test
motivation: a failing test hinted to a thread safety issue, which was then diagnosed to an incorrect lock on an array. this prompted creating a thread safe utility for array to avoid such cases
changes: