Skip to content

Commit

Permalink
Use barrier flag in ConnectionRepository because the work item mutate…
Browse files Browse the repository at this point in the history
…s the state on a concurrent queue (#2987)
  • Loading branch information
laevandus committed Jan 31, 2024
1 parent de8ae78 commit 1121a07
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Add new `TextLinkDetector` for parsing and detecting links given a string [#2984](https://github.com/GetStream/stream-chat-swift/pull/2984)
### 🐞 Fixed
- Fix message link preview showing empty space when no metadata available [#2984](https://github.com/GetStream/stream-chat-swift/pull/2984)
- Fix threading issue in `ConnectionRepository` [#2985](https://github.com/GetStream/stream-chat-swift/pull/2985)
- Fix threading issues in `ConnectionRepository` [#2985](https://github.com/GetStream/stream-chat-swift/pull/2985), [#2987](https://github.com/GetStream/stream-chat-swift/pull/2987)
- Fix threading issues in `AuthenticationRepository` [#2986](https://github.com/GetStream/stream-chat-swift/pull/2986)

## StreamChatUI
Expand Down
2 changes: 1 addition & 1 deletion Sources/StreamChat/Repositories/ConnectionRepository.swift
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ class ConnectionRepository {
connectionId: String?,
shouldNotifyWaiters: Bool
) {
let waiters: [String: (Result<ConnectionId, Error>) -> Void] = connectionQueue.sync {
let waiters: [String: (Result<ConnectionId, Error>) -> Void] = connectionQueue.sync(flags: .barrier) {
_connectionId = connectionId
guard shouldNotifyWaiters else { return [:] }
let waiters = _connectionIdWaiters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ final class ConnectionRepository_Tests: XCTestCase {
XCTAssertEqual(result?.value, connectionId)
}

func test_connectionId_doesNotDeadlock() {
func test_connectionId_triggersCompletions_whenConcurrentlyCalled() {
let iterations = 100
let expectations = (0..<iterations).map { XCTestExpectation(description: "\($0)") }
DispatchQueue.concurrentPerform(iterations: 100) { index in
Expand Down

0 comments on commit 1121a07

Please sign in to comment.