Skip to content

Commit a2bf37b

Browse files
authored
Read and update token request completions within a single closure for avoiding data race issues (#3683)
1 parent 3a41957 commit a2bf37b

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
33

44
# Upcoming
55

6-
### 🔄 Changed
6+
## StreamChat
7+
### 🐞 Fixed
8+
- Fix an issue where completion handler was called twice after waiting for token refresh [#3683](https://github.com/GetStream/stream-chat-swift/pull/3683)
79

810
# [4.79.0](https://github.com/GetStream/stream-chat-swift/releases/tag/4.79.0)
911
_May 28, 2025_

Sources/StreamChat/Repositories/AuthenticationRepository.swift

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -285,15 +285,13 @@ class AuthenticationRepository {
285285

286286
func completeTokenCompletions(error: Error?) {
287287
let completionBlocks: [(Error?) -> Void]? = tokenQueue.sync(flags: .barrier) {
288-
self._isGettingToken = false
289288
let completions = self._tokenRequestCompletions
290-
return completions
291-
}
292-
completionBlocks?.forEach { $0(error) }
293-
tokenQueue.async(flags: .barrier) {
289+
self._isGettingToken = false
294290
self._tokenRequestCompletions = []
295291
self._consecutiveRefreshFailures = 0
292+
return completions
296293
}
294+
completionBlocks?.forEach { $0(error) }
297295
}
298296

299297
private func updateToken(token: Token?, notifyTokenWaiters: Bool) {

0 commit comments

Comments
 (0)