-
Notifications
You must be signed in to change notification settings - Fork 212
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
🐛 Protect the spacesPerId
variable by a barrier
#1350
Conversation
Fixes Thread 1: EXC_BAD_ACCESS crash that would occur whenever multiple concurrent threads would attempt to mutate `spacesPerId` at the same time
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.
To me the problem seems to stem from loadData()
setting self.graph
from the processingQueue
, which in turn, through its didSet
sets self.spacesPerId
.
getSpace()
on the other hand would normally set it from the main queue.
Perhaps a simpler solution would be to internally protect getSpace()
on the same processingQueue
? 🤔
public func getSpace(withId spaceId: String) -> MXSpace? {
var space: MXSpace?
processingQueue.sync {
space = self.spacesPerId[spaceId]
}
if space == nil, let newSpace = self.session.room(withRoomId: spaceId)?.toSpace() {
space = newSpace
processingQueue.sync {
self.spacesPerId[spaceId] = newSpace
}
}
return space
}
@stefanceriu maybe that could do the trick 🤔. I used a separate queue to be 100% certain that the read/write operations are not conflicting. Unfortunately I currently lack the scope to test this alternative solution you propose. |
It's okay, now that you explained what you intended, I think yours is nicer. I'm happy to merge it after you make those changes. And thank you for taking the time to fix this 👍 |
@stefanceriu pushing the patch shortly. |
@stefanceriu done ✅ |
Looks great, thank you very much! Will merge as soon as the checks finish 👍 |
Fixes Thread 1: EXC_BAD_ACCESS crash that would occur whenever multiple concurrent threads would attempt to mutate
spacesPerId
at the same time.Signed-off-by: Frantisek Hetes f.hetes@gmail.com