Skip to content

[Bug]: Main thread freeze when opening a channel - ChannelUpdater.cleanStaleMidPageStateIfNeeded blocks on performAndWait #4144

Description

@denis-obukhov

Actual behaviour

SDK version: stream-chat-swift / stream-chat-swiftui 5.5.1
Swift: 6 / strict concurrency enabled

When I open a channel, the app freezes for a few seconds. Time Profiler shows the main thread blocked inside:

ChannelUpdater.cleanStaleMidPageStateIfNeeded(for:isInRecoveryMode:)
  └─ writableContext.performAndWait { ... }
       └─ channelDTO.cleanAllMessagesExcludingLocalOnly()
       └─ writableContext.save()

This runs synchronously at the start of ChannelUpdater.update(), which is called from ChatChannelController.synchronize(). Since synchronize() is @mainactor and ChatChannelViewModel calls it in init, the UI thread blocks until Core Data finishes.

Everything worked flawlessly on version 4.97.0.
On v5.1.0 it was better than on v5.2.0
Unfortunately, starting from version 5.2.0, the app has become extremely problematic

Expected behaviour

Opening a channel should feel instant.

Steps to reproduce

Connect a user with a non-trivial inbox (many channels, some with long history).
Open a channel
Navigate back to the channel list.
Open the same/other channel again.

Which packages are you using?

No response

Which SDK version are you using?

5.5.1

Which iOS version is the issue reproducible?

iOS 26.3, 26.4, 26.5

Which iPhone Device is the issue reproducible?

Any

Which Xcode version are you using?

Xcode 26.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions