Skip to content

Fix crash in ChannelAvatarsMerger when accessing shared properties #858

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

Merged
merged 6 commits into from
Jun 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

# Upcoming

### 🔄 Changed
### 🐞 Fixed
- Fix rare concurrency crash in `ChannelAvatarsMerger.createMergedAvatar(from:)` [#858](https://github.com/GetStream/stream-chat-swiftui/pull/858)

# [4.79.1](https://github.com/GetStream/stream-chat-swiftui/releases/tag/4.79.1)
_June 03, 2025_
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ public class ChannelAvatarsMerger: ChannelAvatarsMerging {
@Injected(\.images) private var images

/// Context provided utils.
private lazy var imageProcessor = utils.imageProcessor
private lazy var imageMerger = utils.imageMerger
private var imageProcessor: ImageProcessor { utils.imageProcessor }
private var imageMerger: ImageMerging { utils.imageMerger }

/// Placeholder images.
private lazy var placeholder1 = images.userAvatarPlaceholder1
private lazy var placeholder2 = images.userAvatarPlaceholder2
private lazy var placeholder3 = images.userAvatarPlaceholder3
private lazy var placeholder4 = images.userAvatarPlaceholder4
private var placeholder1: UIImage { images.userAvatarPlaceholder1 }
private var placeholder2: UIImage { images.userAvatarPlaceholder2 }
private var placeholder3: UIImage { images.userAvatarPlaceholder3 }
private var placeholder4: UIImage { images.userAvatarPlaceholder4 }
Comment on lines +24 to +31
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to replicate the crash with unit tests? We have a couple of unit tests that cover this type of scenario, where we access objects from multiple threads, and ensure it does not crash. Can we add a test for this as well, to avoid future potential regressions? 🙏

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Added


/// Creates a merged avatar from the given images
/// - Parameter avatars: The individual avatars
Expand Down
14 changes: 9 additions & 5 deletions StreamChatSwiftUI.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
/* Begin PBXBuildFile section */
402C54482B6AAC0100672BFB /* StreamChatSwiftUI.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8465FBB52746873A00AF091E /* StreamChatSwiftUI.framework */; };
402C54492B6AAC0100672BFB /* StreamChatSwiftUI.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 8465FBB52746873A00AF091E /* StreamChatSwiftUI.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
4F03F18F2E0140C6001C71A2 /* ChannelAvatarsMerger_Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4F03F18E2E0140C6001C71A2 /* ChannelAvatarsMerger_Tests.swift */; };
4F077EF82C85E05700F06D83 /* DelayedRenderingViewModifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4F077EF72C85E05700F06D83 /* DelayedRenderingViewModifier.swift */; };
4F198FDD2C0480EC00148F49 /* Publisher+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4F198FDC2C0480EC00148F49 /* Publisher+Extensions.swift */; };
4F65F1862D06EEA7009F69A8 /* ChooseChannelQueryView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4F65F1852D06EEA5009F69A8 /* ChooseChannelQueryView.swift */; };
Expand Down Expand Up @@ -610,6 +611,7 @@

/* Begin PBXFileReference section */
4A65451E274BA170003C5FA8 /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; };
4F03F18E2E0140C6001C71A2 /* ChannelAvatarsMerger_Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChannelAvatarsMerger_Tests.swift; sourceTree = "<group>"; };
4F077EF72C85E05700F06D83 /* DelayedRenderingViewModifier.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DelayedRenderingViewModifier.swift; sourceTree = "<group>"; };
4F198FDC2C0480EC00148F49 /* Publisher+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Publisher+Extensions.swift"; sourceTree = "<group>"; };
4F65F1852D06EEA5009F69A8 /* ChooseChannelQueryView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChooseChannelQueryView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2020,17 +2022,18 @@
84C94C7D27567CC2007FE2B9 /* ChatChannelList */ = {
isa = PBXGroup;
children = (
84C94C7F27567D3F007FE2B9 /* ChatChannelListViewModel_Tests.swift */,
84C94D432757C704007FE2B9 /* MoreChannelActionsViewModel_Tests.swift */,
4F03F18E2E0140C6001C71A2 /* ChannelAvatarsMerger_Tests.swift */,
84C94D67275A6AFD007FE2B9 /* ChannelHeaderLoader_Tests.swift */,
849894942AD96CCC004ACB41 /* ChatChannelListItemView_Tests.swift */,
84C94D412757C16D007FE2B9 /* ChatChannelListTestHelpers.swift */,
848399EB275FB41B003075E4 /* ChatChannelListView_Tests.swift */,
84DEC8DA27609FA200172876 /* MoreChannelActionsView_Tests.swift */,
84C94C7F27567D3F007FE2B9 /* ChatChannelListViewModel_Tests.swift */,
84D6B55927DF6EC7009C6D07 /* LoadingView_Tests.swift */,
91B763A5283EB39600B458A9 /* MoreChannelActionsFullScreenWrappingView_Tests.swift */,
84DEC8DA27609FA200172876 /* MoreChannelActionsView_Tests.swift */,
84C94D432757C704007FE2B9 /* MoreChannelActionsViewModel_Tests.swift */,
84DEC8DC2760A10500172876 /* NoChannelsView_Tests.swift */,
8413D90127A9654600A89432 /* SearchResultsView_Tests.swift */,
84D6B55927DF6EC7009C6D07 /* LoadingView_Tests.swift */,
849894942AD96CCC004ACB41 /* ChatChannelListItemView_Tests.swift */,
);
path = ChatChannelList;
sourceTree = "<group>";
Expand Down Expand Up @@ -3082,6 +3085,7 @@
84C94D66275A660B007FE2B9 /* MessageActionsViewModel_Tests.swift in Sources */,
84C94D0827578BF2007FE2B9 /* MockFunc.swift in Sources */,
84B2B5CA281947E100479CEE /* ViewFrameUtils.swift in Sources */,
4F03F18F2E0140C6001C71A2 /* ChannelAvatarsMerger_Tests.swift in Sources */,
8423C342277CBA280092DCF1 /* TypingSuggester_Tests.swift in Sources */,
84507C9A281ACCD70081DDC2 /* AddUsersView_Tests.swift in Sources */,
4F8D64402DDDCF9300026C09 /* MessageRelativeDateFormatter_Tests.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//
// Copyright © 2025 Stream.io Inc. All rights reserved.
//

@testable import StreamChatSwiftUI
@testable import StreamChatTestTools
import XCTest

final class ChannelAvatarsMergerTests: StreamChatTestCase {
private var merger: ChannelAvatarsMerger!

override func setUp() {
super.setUp()
merger = ChannelAvatarsMerger()
}

override func tearDown() {
super.tearDown()
merger = nil
}

func testConcurrentCalls() {
let sourceImages: [UIImage] = [
XCTestCase.TestImages.chewbacca.image,
XCTestCase.TestImages.r2.image,
XCTestCase.TestImages.vader.image,
XCTestCase.TestImages.yoda.image
]
DispatchQueue.concurrentPerform(iterations: 100) { _ in
let images = Array(sourceImages.prefix((1...4).randomElement()!))
let mergedImage = merger.createMergedAvatar(from: images)
XCTAssertNotNil(mergedImage)
}
}
}
Loading