You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#3699 highlighted an issue with this pattern where there's a race condition when
The Task uses the value from the publisher
The async method called awaits something and then uses that value.
The publisher is called multiple times in close succession.
This is obvious when you think about it, but this was the first instance where we saw the race condition in action. At this time, searching for the following regex reveals 27 instances of Tasks inside of .sinks.
It needs some work, as it never finishes searching (either in Xcode or via SwiftLint). A faster one is as follows, but it doesn't find instances where there's a block before the task:
#3699 highlighted an issue with this pattern where there's a race condition when
await
s something and then uses that value.This is obvious when you think about it, but this was the first instance where we saw the race condition in action. At this time, searching for the following regex reveals 27 instances of
Task
s inside of.sink
s.\.sink\s*\{[^\}]*?(?:\s*\{[^\}]*?\}[^\}]*?)*\s*Task\s*\{(?:[^{}]*|\{[^{}]*\})*\}
Note about the regex:
It needs some work, as it never finishes searching (either in Xcode or via SwiftLint). A faster one is as follows, but it doesn't find instances where there's a block before the task:
\.sink\s*\{[^\}]*?Task\s*\{(?:[^{}]*|\{[^{}]*\})*\}
Looking at the 27 instances only 3 of them (at the time of writing) really meet the requirements for being an issue:
element-x-ios/ElementX/Sources/Services/Timeline/TimelineController/MockRoomTimelineController.swift
Lines 155 to 163 in a70189d
element-x-ios/ElementX/Sources/UITests/UITestsNotificationCenter.swift
Lines 27 to 35 in a70189d
element-x-ios/ElementX/Sources/Screens/BlockedUsersScreen/BlockedUsersScreenViewModel.swift
Lines 35 to 38 in a70189d
We could go about fixing this in 2 ways:
for await in
which would be tedious.asyncSink
method on Publisher that wraps everything up neatly make sure we finish processing one value before the next and use this instead.Either way we should also add a SwiftLint rule to prevent us doing this in the future.
The text was updated successfully, but these errors were encountered: