pointfreeco / swift-composable-architecture

A library for building applications in a consistent and understandable way, with composition, testing, and ergonomics in mind.
https://www.pointfree.co/collections/composable-architecture
MIT License
11.91k stars 1.37k forks source link

@Shared can trigger a view update from a thread other than the main thread, which sometimes causes crash #3181

Closed larryonoff closed 3 weeks ago

larryonoff commented 3 weeks ago

Description

There’s an issue where updating @Shared from a thread other than the main thread triggers a warning during debugging and sometimes causes crashes in the release configuration.

Store state was accessed on a non-main thread. …

The "Store" class is not thread-safe, and so all interactions with an instance of "Store" (including all of its scopes and derived view stores) must be done on the main thread

Checklist

Expected behavior

Crashes or warnings do not occur

Actual behavior

Crashlytics reports occasional crashes. Xcode shows warnings during debugging.

Steps to reproduce

Refer to the sample project

The Composable Architecture version information

1.11.1

Destination operating system

iOS 17.5.1

Xcode version information

Version 15.4 (15F31d)

Swift Compiler version information

swift-driver version: 1.90.11.1 Apple Swift version 5.10 (swiftlang-5.10.0.13 clang-1500.3.9.4)
Target: arm64-apple-macosx14.0
mbrandonw commented 3 weeks ago

Hi @larryonoff, this will be fixed in #3178 when we require that withLock be @MainActor. I am going to convert this to a discussion for now, so please feel free to continue the discussion over there!